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>
<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 received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---