Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deprecation warning: #apply_finder_options

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!

like image 606
mfaerevaag Avatar asked Sep 06 '13 22:09

mfaerevaag


People also ask

What is deprecation warning in Python?

Deprecation warnings are warnings that indicate the use of a library or feature is suspended and is no longer considered safe to use.

How do you stop a deprecated warning?

You can use the @SuppressWarnings annotation to suppress warnings whenever that code is compiled. Place the @SuppressWarnings annotation at the declaration of the class, method, field, or local variable that uses a deprecated API.

What is deprecation warning in MongoDB?

The MongoDB server has deprecated the count() function in favor of two separate functions, countDocuments() and estimatedDocumentCount() . DeprecationWarning: collection. count is deprecated, and will be removed in a future version.

What is deprecation warning in node JS?

DeprecationWarning errors are logged by the Node. js runtime when your code (or one of the dependencies in your code) calls a deprecated API. These warnings usually include a DEP deprecation code. They are logged using console. error and end up in your CloudWatch logs.


1 Answers

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
like image 137
Peter Brown Avatar answered Nov 03 '22 00:11

Peter Brown