# ActiveRecord update\_attributes with nested hash

**URL:** <https://www.ruby-forum.com/t/activerecord-update-attributes-with-nested-hash/140077>\
**Category:** Rails\
**Created:** [June 10, 2008, 5:06pm UTC](https://www.ruby-forum.com/t/activerecord-update-attributes-with-nested-hash/140077 "2008-06-10T17:06:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrrobert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed655f/32.png) [@mrrobert](https://www.ruby-forum.com/u/mrrobert)\
**Post date:** [June 10, 2008, 5:06pm UTC](https://www.ruby-forum.com/t/activerecord-update-attributes-with-nested-hash/140077/1 "2008-06-10T17:06:16Z")

</div>

Can the parameter hash passed to update\_attributes include nested hashes  
for child models related through has\_many?

For example, if A has many B, can the parameter hash passed to A  
include a nested hash for B?

It seems the hash can include attributes for A e.g. one level deep.

Thanks for any advice…

---

<div class="post-metadata">

**Author:** ![mrrobert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed655f/32.png) [@mrrobert](https://www.ruby-forum.com/u/mrrobert)\
**Post date:** [June 10, 2008, 7:44pm UTC](https://www.ruby-forum.com/t/activerecord-update-attributes-with-nested-hash/140077/2 "2008-06-10T19:44:48Z")

</div>

Yes, but update\_attributes will look for a child\_hash\_name= method in  
your model. It’ll pass in the child hash. Check out the “complex  
forms” railscasts–that goes over everything you need.
