-
Notifications
You must be signed in to change notification settings - Fork 59
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
Raise unless Ransack ignore_unknown_conditions? #63
base: master
Are you sure you want to change the base?
Conversation
Unfortunately, this does not work with the sort parameter (which uses the same function I modified). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, in the next version v1.8 Ransack will be a soft-dependency.
@@ -17,6 +17,9 @@ def self.extract_attributes_and_predicates(requested_field) | |||
.detect_and_strip_from_string!(field_name) | |||
predicates << Ransack::Predicate.named(predicate) | |||
end | |||
unless predicates.present? || Ransack.options[:ignore_unknown_conditions] | |||
raise ArgumentError, "No valid predicates for #{requested_field}" | |||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I think this is handled already by Ransack:
https://github.com/stas/jsonapi.rb/blob/master/lib/jsonapi/patches.rb#L6
Just reset the option in your config and it should work, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stas: It seems to be ignored, from my testing.
Thank you for this, @sienic. FWIW I decided to slightly slightly change your solution so that ActionController::BadRequest is raised instead of ArgumentError, resulting in a 400 response to the client instead of 500. |
@CofenseLabs-Doug 👍 |
What is the current behavior?
#62
What is the new behavior?
It allows to use the
Ransack
configuration propertyignore_unkown_conditions
with the same semantics as in Ransack.A disadvantage of this solution is that
Ransack
so far has been a dependency ofjsonapi.rb
, and not necessarily of the projects which useJsonapi.rb
. Somehow it could be considered a co-dependency ofjsonapi.rb
, but that is not up to me.Another solution would be to add a configuration object to
jsonapi.rb
.Checklist
Please make sure the following requirements are complete:
features)