未定义的方法'paginate'

时间:2016-09-30 20:26:40

标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-4 ruby-on-rails-5 will-paginate

我正在尝试使用will_paginate gem,但在标题中出现此错误。 我查看了下面的帖子并做了更改,但没有运气

http://stackoverflow.com/questions/17105715/undefined-method-paginate

这就是我所拥有的

应用/控制器/ books_controller.rb

class BooksController < ApplicationController
    def index
    #@books = Book.all
    @books = Book.paginate :page => params[:page], :per_page => 10
    end
end

index.html.erb:

<%= will_paginate @books %>

的Gemfile

gem 'will_paginate', '~> 3.0.4'

Enbironment.rb

gem 'will_paginate'

这是我得到的错误:

undefined method `paginate' for #<Class:0x007fd539118a30>

1 个答案:

答案 0 :(得分:4)

安装gem后重新启动服务器。