ruby on rails-will_pagente宝石问题



所以我试图使用will_page-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)

捆绑安装表明宝石就在那里:

有人知道我在哪里犯的错吗?谢谢,

Matt

尝试使用

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

我只使用

gem 'will_paginate'

在我的Gemfile中,它可以工作

试着把它放在你的Gemfile中:

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

尝试删除"all"。我也遇到了同样的问题,因为我删除了"全部",现在它起作用了。我的代码以前是这样的:.all.paginate:per_page=>events_per_page,:page=>params[:page]在分页之前删除"all"。希望它对你有用。:)

相关内容

  • 没有找到相关文章

最新更新