1

My two models:

Object embeds_one 'sub_object'
SubObject embeds_many 'sub_sub_objects'

This is my params hash:

{"object"=>
  {"sub_object_attributes"=>
    {"sub_sub_objects_attributes"=>
      {"5369627153657208e5000000"=>{"status"=>"inactive"}}}},
 "action"=>"update",
 "controller"=>"objects",
 "id"=>"535e97a953657252fa170000"}

These are my strong params settings:

params.require(:object).permit(sub_object_attributes: {:sub_sub_objects_attributes=>[:id, :status]})

I'm getting the following error from strong_params:

Unpermitted parameters: 5369627153657208e5000000

How do I allow the sub_sub_objects_attributes hash which uses the object IDs as keys?

wurde
  • 2,487
  • 2
  • 20
  • 39
user1032752
  • 751
  • 1
  • 11
  • 28
  • I don't think using `object_id` as key is a good idea. On the receiving side, you cannot retrieve the status associated with the object id because you don't know what object id is. The only way to get the status back is iterate through all key-value pairs of the hash and look for an key that looks like object id. – Arie Xiao May 09 '14 at 02:03
  • Thanks for your reply. Though I'm not sure if I completely follow what you're saying. To clarify, the hash keys are the `id` attributes of the object not the `object_id`. This is the standard behavior for the `fields_for` helper when used with a one-to-many relation as per the Rails docs. – user1032752 May 09 '14 at 14:01

1 Answers1

0

I got it working by scrapping the fields_for helper and manually naming the fields as so:

text_field_tag 'object[sub_object_attributes][sub_sub_objects_attributes][]status'

However, I'd be interested to find out what the correct way to do it using the fields_for helper is.

user1032752
  • 751
  • 1
  • 11
  • 28