I'm working on a project that has the following setup
I have a table called Assessment
for each assessment there can be different reasons and consequences defined for that assessment
then for each assessment the teacher takes multiple data entries over a period of time
each data entry can choose multiple reasons and consequences from the ones defined in the assessment
So you have assessment
has_many :reasons
accepts_nested_attributes_for :reasons
has_many :consequences
accepts_nested_attributes_for :consequences
has_many :data_entries
accepts_nested_attributes_for :data_entries
Then reasons
belongs_to :assessment
has_and_belongs_to_many :data_entries
Then consequences
belongs_to :assessment
has_and_belongs_to_many :data_entries
Finally data_entries
belong to assessment
has_and_belongs_to_many :reasons
has_and_belongs_to_many :consequences
There is also a join table for reasons to data_entries, and consequences to data_entries
The nested table works fine for the reasons, consequences, and the base data_entries
however what I cannot get to work is the reasons and consequences chosen in the data_entries
what appears to be happening in params is that assessment comes back with data_entries_attributes under it
however there is also a data_entry param coming back as well, so it is not part of assessment, so the nest is wrong somehow...
I have this working in other places however this nest is one level deeper than the others...
The way I have the nested form section setup is this...
<td>
<div class="multi-column">
<ul>
<% @assessment.reasons.each do |reason| -%>
<ul>
<%= check_box_tag('data_entry[reason_ids][]',
reason.id, @assessment.reason_ids.include?(
reason.id), :multiple => true) %>
<span rel="tooltip" title="<%= reason.assessment_id %>"><%=
reason.name %></span>
</ul>
<% end %>
</ul>
</div>
</td>
<td>
<div class="multi-column">
<ul>
<% @assessment.consequences.each do |consequence| -%>
<ul>
<%= check_box_tag('data_entry[consequence_ids][]',
consequence.id, @assessment.consequence_ids.include?(
consequence.id), :multiple => true) %>
<span rel="tooltip" title="<%= consequence.assessment_id %>"><%=
consequence.name %></span>
</ul>
<% end %>
</ul>
</div>
</td>
John