-
-
Notifications
You must be signed in to change notification settings - Fork 795
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
Round-trip problem with empty params #366
Comments
Hi @daniel-rikowski, thank you for reporting this issue. The In def initialize(object, params = {}, options = {})
params = {} unless params.is_a?(Hash)
(params ||= {}).delete_if { |k, v| [*v].all? { |i| i.blank? && i != false } }
@context = Context.for(object, options)
@context.auth_object = options[:auth_object]
@base = Nodes::Grouping.new(@context, 'and')
build(params.with_indifferent_access)
end |
Hello @jonatack I'm using Ruby 2.0.0p451, Rails 4.1 and Ransack 1.2.3. I'll try to work on this this week and hopefully make a pull request soon :) |
@daniel-rikowski Super. Which Ransack are you using? The official release, the |
I've checked again today and both branches have the same problem. But in my situation it's not only def ransack(params = {}, options = {})
Search.new(self, params ? params.delete_if {
|k, v| v.blank? && v != false } : params, options)
end At both places the BTW: Why is |
Fixed with 28433f9. |
tl;dr: I've noticed a small problem with empty search queries if the params are piped through
url_for
(orlink_to
) and then redirected to Ransack again.Long example:
/orders?utf8=✓&q[id_eq]=&q[order_code_cont]
and subsequentially processed by Ransack viaOrder.search(params[:q])
.Order.search
is executed the params hash looks like this:Order.search
is executed the params hash looks like this:Most likely this is because of #201
The actual problem shows when I'm using
url_for
(in this case to add apage
param)url_for(params.merge(page: 2))
generates this url:/orders?utf8=✓&q=&page=1
Suddenly Ransack has to handle an (empty) string instead of a hash which leads to various exceptions.
I can think of two ways to fix this: Either don't change
params
(e.g. useparams.dup
before callingdelete_if
) or useparams.presence
at the necessary locations. (AtRansack::Adapters::ActiveRecord::Base.ransack
andRansack::Helpers::FormHelper.sort_link
)Thank you in advance!
The text was updated successfully, but these errors were encountered: