-
-
Notifications
You must be signed in to change notification settings - Fork 808
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
Recent scopes addition broke #search(params[:q]) API #403
Comments
Thanks @ohaibbq, I have to admit that I haven't been using the new If you have the chance to submit a fix and a test that would be great. |
No problem.. This is definitely a design call that I don't feel that comfortable making. Should we accept |
For what it's worth, we have this workaround, maybe worth adding? Ransack.configure do |config|
# If a boolean predicate expects a TRUE_VALUE and it got an empty string
# (shame on you RansackUI!), we should still allow it:
Ransack::Constants::TRUE_VALUES << ""
end The problem is that currently there's no way to distinguish between the intents: params = {"custom_scope" => "true"}
Model.search(params)
#=> Model.custom_scope
#=> Model.custom_scope("true")
#=> Model.custom_scope(true) I assume a bare Model.search({"custom_scope" => "true"})
#=> Model.custom_scope
Model.search({"custom_scope" => ["true"]}
#=> Model.custom_scope("true") As for type conversion, once it's treated as a parameter value inside the array, it's not our place to decide how it gets handled: if you need to write your scope to treat |
Thanks for the response! I'll look in to this workaround soon. I agree that we should make users pass booleans to scopes by wrapping it in an array. Maybe we can justify interpreting string booleans as booleans for applying scopes and add that functionality in to Ransack. |
This implements the solution discussed in activerecord-hackery#403. Fixes activerecord-hackery#403.
This implements the solution discussed in activerecord-hackery#403. Fixes activerecord-hackery#403.
This implements the solution discussed in activerecord-hackery#403. Fixes activerecord-hackery#403.
This implements the solution discussed in activerecord-hackery#403. Fixes activerecord-hackery#403.
Allow passing stringy booleans as scope args. Fixes #403.
@shekibobo wooooo!! thanks for taking the time to do this :) |
Is this feature coming in version 1.5.2? |
Yes. You can use it now with the master branch, please don't hesitate to try it On Monday, November 17, 2014, otaviomedeiros notifications@github.com
|
Thanks @jonatack |
It appears that the recent additions of adding scopes (which is great!) doesn't support the API of passing unmodified
ActionController::Parameters
.Assuming:
Here's a few examples:
Form helper using a hidden input
If the input value is set to
true
, it is deserialized from the request as"true"
.Calling
Person.search(params[:q])
will raiseArgumentError: wrong number of arguments (1 for 0)
as Ransack tries to pass"true"
to the scope.If the hidden value is set to
""
, Ransack skips applying the scope.For now, we are able to manually deserialize these parameters in to the correct values, but just wanted to give you a heads up.
I should be able to look in to ransack's code some more this weekend.
The text was updated successfully, but these errors were encountered: