1

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?

Andrew Grimm
  • 78,473
  • 57
  • 200
  • 338
bigpotato
  • 26,262
  • 56
  • 178
  • 334
  • Not sure so just a comment: try adding the permit method at the end like: permit! And I think this is not recommended. – AME May 27 '14 at 14:34
  • http://stackoverflow.com/questions/14483963/rails-4-0-strong-parameters-nested-attributes-with-a-key-that-points-to-a-hash Check out this question. – AME May 27 '14 at 14:39

1 Answers1

2

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.

zwippie
  • 15,050
  • 3
  • 39
  • 54