Deprecation warning: #apply_finder_options

纵饮孤独 提交于 2019-12-21 04:01:04

问题


I get DEPRECATION WARNING: #apply_finder_options is deprecated. when trying this in my user.rb:

def User.search(search, page)
  paginate page: page,
           per_page: 10,
           conditions: ['name LIKE ?', "%#{search}%"],
           order: 'name'
end

Called through UsersController:

def index
  @users = User.search(params[:search], params[:page])
end

The pagination is done with the will_paginate gem.

What is triggering the warning and how can I fix it? Been trying some googling, but I find the docs not too comprehensive!


回答1:


I'm pretty sure you just need to pull the order and conditions options out of the paginate method and use Active Record for that instead:

def User.search(search, page)
  order('name').where('name LIKE ?', "%#{search}%").paginate(page: page, per_page: 10)
end


来源:https://stackoverflow.com/questions/18667615/deprecation-warning-apply-finder-options

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