Search code examples
ruby-on-railsruby-on-rails-3ruby-on-rails-4ruby-on-rails-5will-paginate

undefined method 'paginate'


I am trying to use will_paginate gem but getting this error in title. I checked the thread below and did the changes but no luck

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

This is what i have

App/Controllers/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'

and this is the error i get:

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

Solution

  • Restart a server after installing a gem.