kaminari undefined method 'page'

送分小仙女□ 提交于 2019-12-05 13:30:51

Kaminari uses paginate_array to paginate an array. 2 solutions:

First, you can use limit(10) instead of first(10):

@songs = Song.limit(10).page(params[:page])

Second, use paginate_array

@songs = Kaminari.paginate_array(Song.first(10)).page(params[:page])

I'd advise you rewrite your controller slightly. Better yet, move your filters to the model or a filter class. Look into present? for testing existence of params as that will check for nil and empty.

def index
  @songs = Song

  @songs = @songs.where("year like ?", params[:year])          if params[:year]
  @songs = @songs.where("artist_name like ?", params[:artist]) if params[:artist]
  @songs = @songs.where("title like ?", params[:song])         if params[:song]

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