I have two models, links and tags, associated through a 3rd model, link_tags. I added the following to my link model,
has_many :tags, :through => :link_tags has_many :link_tags
accepts_nested_attributes_for :tags, :allow_destroy => :false, :reject_if => proc { |attrs| attrs.all? { |k, v| v.blank? } }
and put this in a partial called by the new and edit forms for links,
<%= f.error_messages %>
<p> <%= f.label :uri %><br /> <%= f.text_field :uri %> </p> <p> <%= f.label :title %><br /> <%= f.text_field :title %> </p>
<h2>Tags</h2> <% f.fields_for :tags do |tag_form| %> <p> <%= tag_form.label :name, 'Tag:' %> <%= tag_form.text_field :name %> </p> <% unless tag_form.object.nil? || tag_form.object.new_record? %> <p> <%= tag_form.label :_delete, 'Remove:' %> <%= tag_form.check_box :_delete %> </p> <% end %> <% end %>
<p> <%= f.submit 'Update' %> </p>
The POST on submit fails with the following error:
Tag(#-621698598) expected, got Array(#-609734898)
Does anyone know the necessary steps to do this? I've been basing it off the multi-model section of this: Getting Started with Rails — Ruby on Rails Guides , but it seems incomplete for has_many => :through.
Thanks, Andrew