# Multiple Models, one form, has\_many AND has\_one not workink

**URL:** <https://www.ruby-forum.com/t/multiple-models-one-form-has-many-and-has-one-not-workink/155695>\
**Category:** Rails\
**Created:** [December 15, 2008, 5:09pm UTC](https://www.ruby-forum.com/t/multiple-models-one-form-has-many-and-has-one-not-workink/155695 "2008-12-15T17:09:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![zbo09](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/a183cd/32.png) [@zbo09](https://www.ruby-forum.com/u/zbo09)\
**Post date:** [December 15, 2008, 5:09pm UTC](https://www.ruby-forum.com/t/multiple-models-one-form-has-many-and-has-one-not-workink/155695/1 "2008-12-15T17:09:34Z")

</div>

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