简体   繁体   English

宝石kaminari中的分页错误?

[英]Pagination error in gem kaminari?

I am working on rails 4 and this are my steps:- 我正在使用rails 4 ,这是我的步骤:-

  1. gem kaminari --in gemfile gem kaminari 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) @vendors = Vendor.order(:name).page params[:page] vendor_controller.rb)也试图@vendors=Vendor.order("name").page(params[:page]).per(5)
  4. <% = paginate @vendors %> in index.html.erb index.html.erb <% = paginate @vendors %>

Error:- 错误:-

undefined method `page' for #<ActiveRecord::Relation::ActiveRecord_Relation_Vendor:0x16bec10>

I have also tried in console 我也在console尝试过

Vendor.count                 
a = Vendor.limit(5).count     
b = a.page(1).per(20).size

Error:- NOmethoderror undefined method 'page' 错误: NOmethoderror undefined method 'page'

question:- Where i am going wrong .? 问题:-我要去哪里错了?

Thanks 谢谢

Try calling the page method directly from the ActiveRecord class. 尝试直接从ActiveRecord类调用页面方法。 You're calling it after order, which returns an ActiveRecord::Relation object. 您在订购后调用它,它返回一个ActiveRecord::Relation对象。

@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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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