所以我正在尝试使用will_paginate-rails3并且它在我的控制器中没有解决的问题:
def index
@posts = Post.paginate(:page => params[:page], :per_page => 2 )
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @posts }
end
end
Gemfile:gem "will_paginate-rails3", '~> 3.0.pre'
posts / index.html.erb:<%= will_paginate @posts %>
NoMethodError: NoMethodError (undefined method `paginate' for #<Class:0x12c3438>):
app/controllers/posts_controller.rb:5:in `index'
Rendered C:/Ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.0.3/lib/action_dispatch/middleware/templates/rescues/_trace.erb (0.0ms)
Rendered C:/Ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.0.3/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (0.0ms)
Rendered C:/Ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.0.3/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (15.6ms)
捆绑安装说宝石就在那里:
有人知道我弄错了什么地方吗?谢谢,
马特
答案 0 :(得分:2)
尝试使用
def index
@posts = Post.all.paginate(:page => params[:page], :per_page => 2 )
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @posts }
end
end
答案 1 :(得分:1)
我只使用
gem 'will_paginate'
在我的Gemfile中它可以正常工作
答案 2 :(得分:0)
尝试将其放入Gemfile中:
gem "will_paginate", "~> 3.0.pre2"
答案 3 :(得分:0)
尝试删除“全部”。我有同样的问题,因为我删除了“全部”,它现在有效。 我的代码看起来像这样: .all.paginate:per_page =&gt; events_per_page,:page =&gt; PARAMS [:页面] 删除分页前的“all”。希望对你有效。 :)