<% parent_record = @record associated = column.singular_association? ? [parent_record.send(column.name)].compact : parent_record.send(column.name).to_a associated = associated.sort_by {|r| r.new_record? ? 99999999999 : r.id} unless column.association.options.has_key?(:order) if show_blank_record = column.show_blank_record?(associated) child = column.singular_association? ? parent_record.send(:"build_#{column.name}") : parent_record.send(column.name).build reflection = parent_record.class.reflect_on_association(column.name) if reflection && reflection.reverse reverse_macro = child.class.reflect_on_association(reflection.reverse).macro child.send(:"#{reflection.reverse}=", parent_record) if [:has_one, :belongs_to].include?(reverse_macro) end associated << child end subform_div_id = "#{sub_form_id({:association => column.name, :id => parent_record.id || 99999999999})}-div" -%>
<%= column.label -%>
> <%= render :partial => subform_partial_for_column(column), :locals => {:column => column, :parent_record => parent_record, :associated => associated, :show_blank_record => show_blank_record} %>
<%= link_to_visibility_toggle(subform_div_id, {:default_visible => !column.collapsed}) -%> <% @record = parent_record -%>