ruby on rails - Pagination not working with merged objects -
i have 4 objects
@ob1 = user.where(:area => "india") @ob2 = user.where(:area => "usa") @ob3 = user.where(:area => "uk") @ob4 = user.where(:area => "china")
merged above 4 objects in on object
@merged_obj= @obj1+@obj2
merged object , passing pagination
@users = @merged_obj.paginate(:page => params[:page], :per_page => 1)
but troughs error
nomethoderror: undefined method `paginate' #<array:0x007fc3d65a5338>
pagination works below code:
@users = user.where(:area => "india").paginate(:page => params[:page], :per_page => 1)
gems:-
gem 'will_paginate', '~> 3.1.0' gem 'will_paginate-bootstrap'
it looks won't work arrays. of following instead
@obj = user.where(:area => ["india","usa","uk","china"])
or
@merged_obj = user.where(id: [@ob1.id, @ob2.id, @ob3.id, @ob4.id])
edit: responding comments if denormalizing area not option own pagination on array
@page = @merged_obj[start, pagesize]
Comments
Post a Comment