I am working on rails 4
and this are my steps:-
gem kaminari
--in gemfile @vendors = Vendor.order(:name).page params[:page]
in vendor_controller.rb)
also tried @vendors=Vendor.order("name").page(params[:page]).per(5)
<% = paginate @vendors %>
in index.html.erb
Error:-
undefined method `page' for #<ActiveRecord::Relation::ActiveRecord_Relation_Vendor:0x16bec10>
I have also tried in console
Vendor.count
a = Vendor.limit(5).count
b = a.page(1).per(20).size
Error:- NOmethoderror undefined method 'page'
question:- Where i am going wrong .?
Thanks
Try calling the page method directly from the ActiveRecord
class. You're calling it after order, which returns an ActiveRecord::Relation
object.
@vendors = Vendor.page(params[:page]).order(:name)
I think this one may solve your problem:
vendor.except(:limit, :offset)
In model use:
paginates_per 5
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.