Multiple Models, one form, has_many AND has_one not workink

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| %>

Contact #


<% fields_for “employee[flat_mate_attributes][#{index}]”, flat_mate
do |fm_form| %>

full name:
<%= 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><label>relationship:</label>
  <%= fm_form.select :relationship, ['Partner', 'Friend',

‘Flatmate’], :prompt => true, :index => nil %>

  <% 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’] %>


<% end %>
<% end %>
<h4>Phone</h4>
<p><%= render :partial => 'admin/shared/primary_telephone_number',

:locals => { :telephone => flat_mate.primary_telephone_number } %>

<% 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 %>