will_paginate宝石问题
所以我尝试使用 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)
捆绑包安装说 gem 就在那里:
有人知道我在哪里犯了错误吗?谢谢,
马特
So I'm trying to use will_paginate-rails3 and its not working out here's what I have in my controller:
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)
Bundle install says the gem is there:
Anybody know where I made my mistake? Thanks,
Matt
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试使用
Try using
我只
在 Gemfile 中使用并且它有效
I use just
in my Gemfile and it works
尝试将其放入您的 Gemfile 中:
Try putting this in your Gemfile instead:
尝试删除“全部”。我遇到了同样的问题,因为我删除了“全部”,所以现在可以了。
我的代码曾经是这样的:
.all.paginate :per_page => events_per_page, :page =>;参数[:页]
删除分页前的“全部”。希望它对你有用。 :)
Try to delete the "all". I had the same problem, since I deleted the "all", it works now.
My code used to look like this :
.all.paginate :per_page => events_per_page, :page => params[:page]
delete the "all" before paginate. Hope it works for you. :)