apply_finder_options deprecated in Rails 4 #322

ffmike opened this Issue Jul 13, 2013 · 13 comments

6 participants


If you call will_paginate with AR finder options:

@suppliers = Suppliers.paginate :order => 'name'

You'll end up with a warning from Rails 4:

DEPRECATION WARNING: #apply_finder_options is deprecated. (called from paginate at .../lib/will_paginate/active_record.rb:154)

Easily fixable by changing the original call:

@suppliers = Suppliers.order("name").paginate

The problem is that in Rails 4.1, the original call is going to fail unless the user includes the activerecord_deprecated_finders gem in their project, and this isn't obvious from the error.

Not sure the best way forward here, or I'd submit a PR. I don't think I'd be in favor of will_paginate dragging in activerecord_deprecated_finders itself though. I'd rather have it reject finder options and warn the user to rewrite, but that feels like it might break a lot of existing code.


The solution should be to deprecate the paginate() method in favor of page(). This would result in the same kind of deprecation warning but the error message would at least come from us and could be more helpful.

Patches welcome


These guys got it straight:

Just put the :order out...
Worked for me. Cheers.


apply_finder_options is now gone. It has been moved to 'activerecord-deprecated_finders' in Rails 4.0 and since 4.1 it's no longer a dependency of Rails, but it's still used inside the will_paginate code.

Could we explicitly use 'activerecord-deprecated_finders' on Rails 4.x?


Users who need this functionality should add that gem to their Gemfile. However, I would advise simpley switching all pagination calls to the Arel syntax to avoid this dependency altogether.


It looks like just the Gemfile doesn't help, will_paginate/lib/will_paginate/active_record.rb still needs to explicitly require the 'activerecord-deprecated_finders' on Rails 4.1.

@nathany nathany referenced this issue Jun 17, 2014

Testing against Rails 4.1+ #388

3 of 5 tasks complete
@mislav mislav added the todo label Jun 18, 2014

The way in which this is handled now is to catch a LoadError that may occur when trying to load activerecord-deprecated_finders, but this isn't a robust method, and it may fail when e.g. bundler is not used or activerecord-deprecated_finders is in the load path for another reason. Would it not be better to test the activerecord version instead? Something like:

if ActiveRecord::VERSION::MAJOR >= 4
  require 'active_record/deprecated_finders'

This will also produce a more explicit failure with Rails 4.1 applications without activerecord-deprecated_finders in the Gemfile.


Any reason why this hasn't been fixed yet? I shouldn't have to add the activerecord-deprecated_finders gem to use this gem in Rails 4+


@deanperry And you don't need to add the gem to use will_paginate in Rails 4+. Is something giving you trouble? Are you getting exceptions? Can we see the invocation code?


I've sorted it. I'm upgrading a Rails 3.2 app to 4.2 and turns out it was some old conditions: model code that was causing the issues. Sorry!


Correct, because apply_finder_options was deprecated and now unavailable, you can't have calls like

User.paginate(per_page: 30, conditions: "...", order: "created_at DESC")

That's alright, because since Arel we can all just do

User.where(...).order("created_at DESC").limit(30).page(params[:page])

Yep, I didn't write the original code and it was a bit confusing. I ended up scrapping it and using the gem Ransack for searching :)


I am having a hard time trying to understand how to rewrite the following so as not to get this error. In my case I have multiple search fields. The above only shows a single condition. Sorry for my lack of knowledge.

My current code is:
@search =[:q])
@customers = @search.result.paginate(page: params[:page], :per_page => 30, :order => 'last_name ASC')

I get the .order, .limit and .page, just not sure what needs to go into the .where section since there are 3 different fields that can be searched on in the customers.

@bf4 bf4 referenced this issue in rails-api/active_model_serializers Aug 20, 2015

Pagination Links #1041

@mislav mislav added a commit that referenced this issue Jan 3, 2016
@mislav Merge branch 'test-compat'
Fixes #462
Closes #440, #330, #326, #322

I've dropped use of apply_finder_options in master.

@mislav mislav closed this Jan 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment