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!
Deprecation warnings are warnings that indicate the use of a library or feature is suspended and is no longer considered safe to use.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With