Undefined method `paginate'

will_paginate doesn't work like that. paginate is a method of the Location class:

def index
  @locations = Location.paginate(page: params[:page], per_page: 10) 
  respond_to do |format|
    format.html
    format.json { render json: @locations }
  end 
end

Moreover, to use will_paginate you should just need to add the line below in your Gemfile, no modification in environment.rb is required:

gem "will_paginate", "~> 3.0.4" 

You try to paginate array. Try this:

def index
   @locations = Location.paginate(:page => params[:page], :per_page => 10)   

     respond_to do |format|
      format.html  #index.html.erb
      format.json { render json: @locations }
    end 
  end

If you want to paginate array see Paginating an Array in Ruby with will_paginate


Make sure to restart the server after installing the 'will_paginate' gem.

This was the stupid issue in my case.