Forum: Ruby on Rails Multiple Models, one form, has_many AND has_one not workink

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Darran T. (Guest)
on 2008-12-15 18:09
I have a model (Employee) which has a has_many association with
(FlatMate). A flat mate also has a has_one association (PrimaryAddress).
Now when I try to create a form and then submit it I receive the 500
expected hash error.

Can anyone help me out?

Here's my view:

<% form_for [:admin, @employee] do |f| %>

  <%= render :partial => 'essential_details', :locals => { :f => f } %>
  <%= render :partial => 'next_of_kin', :locals => { :kin =>
@employee.kin } %>

  <%=
  #render :partial => 'flat_mate', :collection => @employee.flat_mates
  %>

  <% @employee.flat_mates.each_with_index do |flat_mate, index| %>
    <fieldset>
    <h3>Contact #</h3>
    <% fields_for "employee[flat_mate_attributes][#{index}]", flat_mate
do |fm_form| %>
      <p><label>full name: </label>
      <%= fm_form.text_field :first_name, :size => 25, :index => nil %>
      <%= fm_form.text_field :initial, :size => 2, :index => nil %>
      <%= fm_form.text_field :surname, :size => 25, :index => nil %>

      <%= do_error flat_mate, :first_name %> <%= do_error flat_mate,
:surname %></p>

      <p><label>relationship:</label>
      <%= fm_form.select :relationship, ['Partner', 'Friend',
'Flatmate'], :prompt => true, :index => nil %></p>

      <% fields_for
"employee[flat_mate_attributes][#{index}][primary_address_attributes]",
flat_mate.primary_address do |address_form| %>
        <%= address_form.hidden_field :address_type, :value => 'Main' %>

        <p><label>street:</label>
        <%= address_form.text_field :street %></p>

        <p><label>city/town:</label>
        <%= address_form.text_field :city %></p>

        <p><label>zip/post code:</label>
        <%= address_form.text_field :post_code %></p>

        <p><label>state/county:</label>
        <%= address_form.text_field :county %></p>

        <p><label>country:</label>
        <%= address_form.country_select :country, ['United Kingdom',
'Northern Ireland', 'Ireland', 'United States'] %></p>
      <% end %>
    <% end %>

    <h4>Phone</h4>
    <p><%= render :partial => 'admin/shared/primary_telephone_number',
:locals => { :telephone => flat_mate.primary_telephone_number } %></p>

    <% unless flat_mate.new_record? %>
      <%= fm_form.hidden_field :id, :index => nil %>
      <%= fm_form.hidden_field :should_destroy, :index => nil, :class =>
'should_destroy' %>
    <% end %>
  <% end %>

  <%= render :partial => 'user_details', :locals => { :user =>
@employee.user } %>

  <%= submit_tag 'create' %>
<% end %>
This topic is locked and can not be replied to.