Undefined method `paginate'

好久不见. 提交于 2019-12-05 02:05:29

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" 
Sebyddd

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

This was the stupid issue in my case.

Alexander Kobelev

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!