Skip to content
This repository has been archived by the owner on Aug 17, 2017. It is now read-only.

Array of possible values for a key. #167

Open
gotjosh opened this issue Sep 18, 2013 · 6 comments
Open

Array of possible values for a key. #167

gotjosh opened this issue Sep 18, 2013 · 6 comments

Comments

@gotjosh
Copy link

gotjosh commented Sep 18, 2013

Is it possible to pass an Array of values for a given key? I'm wondering if this should be something within the scope of strong params or if it belongs outside of this.

Something like

params.require(:user).permit(:name, role: ["editor", "reader"], :bio)
@ka8725
Copy link

ka8725 commented Sep 19, 2013

Of course it's possible but you pass params in the wrong order. The right order should be :name, :bio, role: ["editor", "reader"]

@gotjosh
Copy link
Author

gotjosh commented Sep 19, 2013

Thank You! I have submitted a pull request. To document such feature. It's Issue #169.

@jhephs
Copy link

jhephs commented Sep 18, 2014

Is this still working? Tried it just recently with Rails 4.1 and it seems not to be working anymore. :(

@doits
Copy link

doits commented Oct 17, 2014

Stumbled across this too. Tested with Rails 4.2.0.beta2 and this does not work?

ActionController::Parameters.new({:bla => 'blub'}).permit(:bla => ['blub'])
=> {"bla"=>nil}

As this use case is not documented, it might be reasonable this does not work. But this might be a nice feature to implement, then :-)

@amngibson
Copy link

Did this ever get resolved in rails 4? Looking to filter role values on signup with devise and this looked like the only solution.

@greyvugrin
Copy link

@gotjosh found this because I was following a similar approach. If you're going to use those params to create a user it seems like doing the validation in the model is the way to go:

http://stackoverflow.com/questions/16818117/rails-where-to-add-validation-code-controller-or-model

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

No branches or pull requests

6 participants