will_paginate宝石问题

发布于 2024-11-16 00:52:51 字数 1089 浏览 0 评论 0原文

所以我尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

眼前雾蒙蒙 2024-11-23 00:52:51

尝试使用

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

Try using

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
残疾 2024-11-23 00:52:51

我只

gem 'will_paginate'

在 Gemfile 中使用并且它有效

I use just

gem 'will_paginate'

in my Gemfile and it works

北座城市 2024-11-23 00:52:51

尝试将其放入您的 Gemfile 中:

gem "will_paginate", "~> 3.0.pre2"

Try putting this in your Gemfile instead:

gem "will_paginate", "~> 3.0.pre2"
失与倦" 2024-11-23 00:52:51

尝试删除“全部”。我遇到了同样的问题,因为我删除了“全部”,所以现在可以了。
我的代码曾经是这样的:
.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. :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文