fields_for items not updating child records??

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 --> <h4>Property Information:</h4> <div id="top_background1"><strong>Property No:</strong><br> <%=f.text_field :s_account_no, :size => '10'%> </div> <br>

<!--Customer Information-->

<div id="Customer_info">

<h4>Customer Information</h4>   <%fields_for @account.customer do |customer_fields|%> <br> <div style='padding-left:30px;margin-top:-12px;'>Name: < %=customer_fields.text_field :name, :size => '48'%></div><br> <div style='padding-left:30px;margin-top:-12px;'>Address: < %=customer_fields.text_field :address, :size => '48'%></div><br> <div style='padding-left:0px;margin-top:-15px;'>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'%></

<div style="padding-left:425px"> </div>

<%end%>

  </div> <br> <br> <!--Owner Information-->

<div id="Owner_info">

<h4>Owner Information</h4>   <%fields_for @account.owner do |i|%> <br> <div style='padding-left:30px;margin-top:-12px;'>Name: < %=i.text_field :name, :size => '48'%></div><br> <div style='padding-left:30px;margin-top:-12px;'>Address: < %=i.text_field :address, :size => '48'%></div><br> <div style='padding-left:0px;margin-top:-15px;'>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'%></div> <div style="padding-left:425px"> </div>

<%end%>

  </div>

<%= submit_tag "Update Account" %> <%end%>

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

Chris

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.

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

Any help is greatly appreciated.

Chris