# Nested Model Forms

**URL:** <https://discuss.rubyonrails.org/t/nested-model-forms/52549>\
**Category:** rubyonrails-talk\
**Created:** [June 24, 2010, 6:08pm UTC](https://discuss.rubyonrails.org/t/nested-model-forms/52549 "2010-06-24T18:08:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anthony\_Gardner](https://avatars.discourse-cdn.com/v4/letter/a/bcef8e/32.png) [@Anthony\_Gardner](https://discuss.rubyonrails.org/u/Anthony_Gardner)\
**Post date:** [June 24, 2010, 6:08pm UTC](https://discuss.rubyonrails.org/t/nested-model-forms/52549/1 "2010-06-24T18:08:12Z")

</div>

I’m trying to get a multi level nested form model working but have hit a problem. In one of my models, I have a habtm association and it’s throwing an error on a nested form and these are check boxes with a method of ‘time\_unit\_ids’.

The nested forms work without the habtm (time\_unit\_ids) so things are pretty much set up okay.

Here’s the set up (obviously well and truly stripped back). Hopefully someone can see something I’m missing.

CIA -ants

Models:

event\_category: has\_many :event\_types accepts\_nested\_attributes\_for :event\_types

event\_type: has\_and\_belongs\_to\_many :time\_units has\_many :events belongs\_to :event\_category accepts\_nested\_attributes\_for :events

event: belongs\_to :event\_type

controller new action has …

```ruby
    @event_category.event_types.build
    @event_category.event_types[0].events.build

Forms:
  event_categories/new.html.erb
  <% form ...... do |form| %>
   <% form.fields_for :event_types do |event_type_form| %>
     <% event_type_form.fields_for :events do |event_form| %>

       <% @time_units.each do |time_unit| %>
          <% name = [time_unit.name](http://time_unit.name); id = [time_unit.id](http://time_unit.id) %>
            <%= event_form.check_box 'time_unit_ids[]', { :id => name }, [time_unit.id](http://time_unit.id) %>

          <% end %>

```

```ruby
undefined method `time_unit_ids[]' for #<EventType:0xb6fa13b8>

```

I fear I may need to do this but it’s not ideal …

\<%= check\_box\_tag ‘event\_category[event\_types\_attributes][0][time\_unit\_ids]’, [time\_unit.id](http://time_unit.id),

```
          { :id => name } %>

```
