弃用警告:#apply_finder_options [英] Deprecation warning: #apply_finder_options

查看:77
本文介绍了弃用警告:#apply_finder_options的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到的不当警告:#apply_finder_options已过时。在我的 user.rb 中尝试此操作时: p>

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

通过 UsersController 调用:

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

分页是使用 will_paginate gem完成的。

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!

推荐答案

我很确定您只需要拉在分页方法之外的订单和条件选项,并使用Active Record代替:

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

这篇关于弃用警告:#apply_finder_options的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆