Skip to content
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

Fix 'permit' params to allow multiple form inputs for a single scope #115

Merged
merged 7 commits into from Mar 8, 2017

Conversation

ayaman
Copy link
Contributor

@ayaman ayaman commented Nov 24, 2016

Resolves #114

@edwardmp
Copy link
Contributor

edwardmp commented Dec 3, 2016

Thanks for this, but in my case it doesn't solve the problem yet. It still complains about a unpermitted parameter.. will investigate further

@edwardmp
Copy link
Contributor

edwardmp commented Dec 3, 2016

Got it. The comparison is_a? Hash returns false in my case, because p is not a Hash but an instance of ActionController::Parameters (not sure why this actually deviates from your situation).

Therefore I propose the following change:
permissible_filter_params << ([ActionController::Parameters, Hash].member?(filterrific_params[p].class) ? { p => filterrific_params[p].keys } : p)

Alternatively, instead of comparing with a fixed list of classes, we could also just check if the instance responds to they keys method.

For now I'll submit a pull request to your pull request containing the former fix.

@edwardmp
Copy link
Contributor

edwardmp commented Dec 3, 2016

I know why it worked in your case. You must have tested on Rails 4 or earlier. Back then ActionController::Parameters inherited from hash, so the comparison to a hash evaluated to true. But starting in Rails 5 this is no longer the case and ActionController::Parameters inherits from Object instead.

Thus, what was actually passed will always be of type ActionController::Parameters. Therefore, I propose to just check that the type conforms to ActionController::Parameters, rather than checking against the Hash type. I'll modify the pull request to account for this.

More info: http://blog.bigbinary.com/2016/07/25/parameters-no-longer-inherit-from-hash-with-indifferent-access-in-rails-5.html

@ayaman
Copy link
Contributor Author

ayaman commented Dec 4, 2016

That makes sense, thank you for the update! I merged your pull request and it seems everything is working fine.

blaedj and others added 3 commits February 14, 2017 11:00
Permit array parameters in filterrific_params. With this change, you can filter
by multiple values from a select.
All credit goes to [@patrocc6](github.com/patrocc6) for this, see
jhund#113 (comment)
ActionController::Parameters no longer inherits from hash in rails 5
Properly permit array params
@blaedj
Copy link
Contributor

blaedj commented Feb 15, 2017

This also fixes #113 now.

@patrickworkit
Copy link

Thanks for fixing this! It would be great to have this merged in.

@edwardmp
Copy link
Contributor

edwardmp commented Mar 7, 2017

@jhund Could you please merge this in, as various important fixes by various contributors are included in this PR, thanks 👍

@jhund jhund merged commit 40ecd19 into jhund:master Mar 8, 2017
@jhund
Copy link
Owner

jhund commented Mar 8, 2017

Thank you for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants