Accepts_nested_attributes_for with has_many => :through

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 %>


<% 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.


have a look:

2010/2/6 acreadinglist [email protected]

“Ruby on Rails: Talk” group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected][email protected]
For more options, visit this group at

tommy xiao
E-mail: xiaods(AT)