-
Notifications
You must be signed in to change notification settings - Fork 164
Permit ActionController::AnyParam on hashes #193
base: master
Are you sure you want to change the base?
Conversation
What is the difference between this and |
It works within the permit, so for example home.permit(owner: [ :name, :age, children: ActionController::AnyParam ] ). So it's to scope the permit all. |
I mean, we already have |
how can you do this |
|
yep, but imagine you have an array of chidren and on each of them there is a girlfriend Hash that you want to permit it all, so then you will need a method to iterate over the array and do what you are doing there permitted = params.permit(owner: [ children: [ :name, :age ] ] )
params[:owner][:children].each_with_index do |child, index|
permited[:owner][:children][index][:girlfriend] = child[:girlfriend]
end An also doing the permit on the children attributes you want there. rather than just doing params.permit(owner: [ children: [ :name, :age, girlfriend: ActionController::AnyParam ] ] And if there is an array within that girlfriend's array it's going to be a mess, because the complexity on doing it will grow exponentially |
I'm almost sure it is possible to do with This repository is only to Rails < 4 support, so if you want this you should submit your pull request to rails/rails. |
@rafaelfranca I found a usecase where You can do it with plain ruby obviously, but I think the purpose of strong_parameters it's also making these things easier. Here's my example: { contact_sources: [
{ id: 1, filled_fields: { randomstuff: 'randomdata', dunno: 123 } },
{ id: 2, filled_fields: { blah: 'blabla', dunno: 9043 } }
] } And what I tried: params.permit(contact_sources: [{:filled_fields => []}, 'id']) Something like this should be enough (it's a very simple idea): params.permit(contact_sources: [{:filled_fields => true}, 'id']) A reference to my original StackOverflow question: http://stackoverflow.com/questions/24794040/allow-an-array-of-hashes-with-a-dynamic-hash-hstore-inside |
A way to support any args within a hash, for Rails APIs this is very useful