3

I'd like to use accepts_nested_attributes_for with Active Resource. Is this possible? I have been experimenting in console and passing in nested attributes works, however the nested models fail to create because the foreign_key is never set.

For example,

I have a user class that accepts_nested_attributes_for :credentials. The JSON comes across as

"user" => { "name" => "Joe", "credentials" => ["username" => "joe", "password" => "password"]}

, so I copied that into console, but the credential validation fails since user_id is never set.

Is there a way to do this?

Eric M.
  • 5,399
  • 6
  • 41
  • 67
  • Works fine if I remove the validation on user_id, but I'd prefer to keep it despite having the validation on the database column. What is the best approach to solve this? – Eric M. Jul 20 '10 at 00:05
  • I'm having the same issue - seems weird. What am I doing wrong? – Nuby May 10 '11 at 01:59
  • Is your problem related with the JSON format of the object? If so, you could specify which attributes are exported to this format. – Guilherme Garnier Sep 05 '12 at 15:54

0 Answers0