-
Notifications
You must be signed in to change notification settings - Fork 864
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
apply_finder_options deprecated in Rails 4 #322
Comments
The solution should be to deprecate the Patches welcome |
These guys got it straight: Just put the :order out... |
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. |
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:
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 |
@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 |
Correct, because 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: 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. |
I've dropped use of |
As far as #apply_finder_options deprecated in Rails 4.1 (See mislav/will_paginate#322)
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 text was updated successfully, but these errors were encountered: