# Fields\_for items not updating child records?

**URL:** <https://www.ruby-forum.com/t/fields-for-items-not-updating-child-records/164880>\
**Category:** Rails\
**Created:** [April 7, 2009, 12:37am UTC](https://www.ruby-forum.com/t/fields-for-items-not-updating-child-records/164880 "2009-04-07T00:37:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![internetchris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c68b51/32.png) [@internetchris](https://www.ruby-forum.com/u/internetchris)\
**Post date:** [April 7, 2009, 12:37am UTC](https://www.ruby-forum.com/t/fields-for-items-not-updating-child-records/164880/1 "2009-04-07T00:37:50Z")

</div>

Hey everyone,

I need some help. I have an accounts controller, and am working with  
the show view. Each account has an “owner” and a “customer”. I can  
create the accounts/owners/customers just fine, but when it comes to  
updating I can’t. I have a single account view, that uses a form, and  
the “fields\_for” command to update the customer and owners when I  
submit the form. The account fields update just fine, but the child  
records (owner, and customer) information does not. Here’s my update  
routine in the controller. I’m pretty new so I’m sure it’s something  
simple I’m missing.

\*\*\*\*\*\*\*account\_controller

def update

@account = Account.find(params[:id])  
if @account.update\_attributes(params[:account])  
flash[:notice] = ‘Account Record Saved’  
redirect\_to(:action=\>‘show’)  
else  
flash[:warning] = ‘Account Record Did Not Save!’  
redirect\_to(:action=\>‘show’)  
end

end

\*\*\*\*\*\*\*account\_“show”\_view

\<% form\_for(:account, @account, :url =\> {:action =\> ‘update’}, :html  
=\> { :multipart =\> true, :method =\> :put }) do |f| %\>

#### Property Information:

**Property No:**  
\<%=f.text\_field :s\_account\_no, :size =\> '10'%\> 
  

#### Customer Information
 \<%fields\_for @account.customer do |customer\_fields|%\>  

Name: \< %=customer\_fields.text\_field :name, :size =\> '48'%\>
  

Address: \< %=customer\_fields.text\_field :address, :size =\> '48'%\>
  

City/State/Zip: \< %=customer\_fields.text\_field :city, :size =\> '28'%\>,\< %=customer\_fields.text\_field :state, :size =\> '2', :maxlength =\> '2'%\> \<%=customer\_fields.text\_field :zip, :size =\> '5', :maxlength =\> '5'%\>
 

\<%end%\>

  
  

#### Owner Information
 \<%fields\_for @account.owner do |i|%\>  

Name: \< %=i.text\_field :name, :size =\> '48'%\>
  

Address: \< %=i.text\_field :address, :size =\> '48'%\>
  

City/State/Zip: \< %=i.text\_field :city, :size =\> '28'%\>,\<%=i.text\_field :state, :size =\> '2', :maxlength =\> '2'%\> \<%=i.text\_field :zip, :size =\> '5', :maxlength =\> '5'%\>

 

\<%end%\>

\<%= submit\_tag “Update Account” %\>  
\<%end%\>

Let me know if you need more info. I’m hoping I missed something easy.

Chris

---

<div class="post-metadata">

**Author:** ![internetchris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c68b51/32.png) [@internetchris](https://www.ruby-forum.com/u/internetchris)\
**Post date:** [April 7, 2009, 4:44am UTC](https://www.ruby-forum.com/t/fields-for-items-not-updating-child-records/164880/2 "2009-04-07T04:44:03Z")

</div>

You might want to try inspecting the params in the controller, add a  
“raise params.inspect” into your update action.

I suspect that it is because you have not provided fields for with the  
parent form, like so:

\<% f.fields\_for @account.owner do |i|%\>

If you don’t put the “f.” in front, rails will simply generate params  
that you can access via “params[:owner]”, whereas you want something  
like “params[:account][:owner]”.

This is one problem, but there might be more.

On Apr 7, 6:37 am, internetchris [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![internetchris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c68b51/32.png) [@internetchris](https://www.ruby-forum.com/u/internetchris)\
**Post date:** [April 7, 2009, 7:41pm UTC](https://www.ruby-forum.com/t/fields-for-items-not-updating-child-records/164880/3 "2009-04-07T19:41:03Z")

</div>

Ok so I made those changes, and I am still having issues. Rather than  
posting the problem on two separate forums, I will simply provide a  
link to the latest problem on the railsforum. Any help is very  
appreciated. Multiple models on a single form seem to be hard to  
accomplish.

[http://railsforum.com/viewtopic.php?id=29044](http://railsforum.com/viewtopic.php?id=29044)

Any help is greatly appreciated.

Chris
