ruby on rails - Can't get plain old many-to-one nested form to save -


i'm on rails 3. have model client has address_id. in client form, have nested address fields. here's address part of form:

  <%= f.fields_for @client.address |address_form| %>     <div class="field">       <%= address_form.label :line1 %><br />       <%= address_form.text_field :line1 %>     </div>     <div class="field">       <%= address_form.label :line2 %><br />       <%= address_form.text_field :line2 %>     </div>     <div class="field">       <%= address_form.label :city %><br />       <%= address_form.text_field :city %>     </div>     <div class="field">       <%= address_form.label :state_id %><br />       <%= select("client[address]", "state_id", state.all.collect {|s| [ s.name, s.id ] }) %>     </div>     <div class="field">       <%= address_form.label :zip %><br />       <%= address_form.text_field :zip %>     </div>   <% end %> 

when try save form, this:

address(#23652762896420) expected, got activesupport::hashwithindifferentaccess(#23652751466220) 

i don't understand means or why i'm getting it. here's params.inspect looks like:

{"commit"=>"update client",  "authenticity_token"=>"cbw1fqcsutxs9x6lktl4zeoekx1cwufurzvzpcshhic=",  "_method"=>"put",  "utf8"=>"\342\234\223",  "action"=>"update",  "id"=>"16",  "client"=>{"name"=>"rosie o'donnell",             "address"=>{"city"=>"grand rapids",                         "line1"=>"216 grandville ave sw",                         "zip"=>"49503",                         "line2"=>"",                         "state_id"=>"1"},             "phone"=>"",             "salon_id"=>"1",             "email"=>""},  "controller"=>"clients"} 

can please tell me what's going on?

see here: http://guides.rubyonrails.org/2_3_release_notes.html#nested-object-forms (it's rails 2.3 article, should apply rails 3 well)

in client model need line:

accepts_nested_attributes_for :address

also, change first line of nested form this:

<%= f.fields_for :address |address_form| %>


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -