简体   繁体   中英

Pagination error in gem kaminari?

I am working on rails 4 and this are my steps:-

  1. gem kaminari --in gemfile
  2. bundle install
  3. @vendors = Vendor.order(:name).page params[:page] in vendor_controller.rb) also tried @vendors=Vendor.order("name").page(params[:page]).per(5)
  4. <% = 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM