1
votes

Due to the complexity of my model relationships and the flexibility in my form, I require that strong params takes all keys for params[:variants].

I'm using the cocoon gem for nested forms, and it generates a random string of digits for every new entry like so:

>> params[:variants]
=> {"1401200245834"=>{"size"=>"M", "price"=>"0.00", "measurements"=>"", "sku"=>""}}

The 1401200245834 is random, so I can't stick it into my permitted params. How would I allow for everything under the :variants key in my params hash?

1
Not sure so just a comment: try adding the permit method at the end like: permit! And I think this is not recommended.AME
stackoverflow.com/questions/14483963/… Check out this question.AME

1 Answers

2
votes

I think this paragraph from the docs is relevant:

To whitelist an entire hash of parameters, the permit! method can be used:

params.require(:variants).permit!

This will mark the :variants parameters hash and any subhash of it permitted. Extreme care should be taken when using permit! as it will allow all current and future model attributes to be mass-assigned.