简体   繁体   English

rails 2.3 will_paginate 2.3.16#的未定义方法&#39;paginate&#39; <Class:0x7f0ed5f13138>

[英]rails 2.3 will_paginate 2.3.16 undefined method `paginate' for #<Class:0x7f0ed5f13138>

I've found a lot of links regarding this problem googling. 我发现了很多有关此问题的链接。 but nevertheless I still get this error after implementing those fixes. 但是尽管如此,在实施这些修复程序后,我仍然会收到此错误。 so my gemfile 所以我的gemfile

gem 'will_paginate', '~> 2.3.16' 宝石'will_paginate','〜> 2.3.16'

environment file 环境文件

config.gem 'will_paginate', :version => '~> 2.3.16' config.gem'will_paginate',:version =>'〜> 2.3.16'

Controller 控制者

  def index
     @events = Event.paginate({:page => params[:page], :per_page => 10})
  end

View: 视图:

<% @events.each do |item| %>
...
<% end %>  
...  
<%= will_paginate @events %>  

I'm using rvm, console commands 我正在使用rvm,控制台命令

rvm 1.8.7 do bundle install 
...
rvm use 1.8.7 do bundle exec rake gems:install

Could anyone help me with this problem? 有人可以帮我解决这个问题吗?

try this one 试试这个

      def index
         @events = Event.all.paginate({:page => params[:page], :per_page => 10})
      end

Note: If u get same error still, then just comment out logic of pagination and insert some records in your database table(model) and then use pagination. 注意: 如果您仍然遇到相同的错误,则只需注释掉分页逻辑,然后在数据库表(模型)中插入一些记录,然后使用分页即可。

You cannot call paginate on a model. 您不能在模型上调用分页。 It can be called on collections like hashes, array, ActiveRecord. 可以在哈希,数组,ActiveRecord之类的集合上调用它。

安装gem后,可能只是重新启动服务器的一种情况。

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

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