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 %>
<%= f.label :uri %>
<%= f.text_field :uri %>
<%= f.label :title %>
<%= f.text_field :title %>
Tags
<% f.fields_for :tags do |tag_form| %><%= tag_form.label :name, 'Tag:' %> <%= tag_form.text_field :name %>
<% unless tag_form.object.nil? || tag_form.object.new_record? %><%= tag_form.label :_delete, 'Remove:' %> <%= tag_form.check_box :_delete %>
<% end %> <% end %><%= f.submit 'Update' %>
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:
, but it seems incomplete for has_many => :through.
Thanks,
Andrew