# Accepts\_nested\_attributes\_for with has\_many =\> :through

**URL:** <https://www.ruby-forum.com/t/accepts-nested-attributes-for-with-has-many-through/183023>\
**Category:** Rails\
**Created:** [February 6, 2010, 9:57am UTC](https://www.ruby-forum.com/t/accepts-nested-attributes-for-with-has-many-through/183023 "2010-02-06T09:57:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![acreadinglist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ccd318/32.png) [@acreadinglist](https://www.ruby-forum.com/u/acreadinglist)\
**Post date:** [February 6, 2010, 9:57am UTC](https://www.ruby-forum.com/t/accepts-nested-attributes-for-with-has-many-through/183023/1 "2010-02-06T09:57:49Z")

</div>

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:

> **[Getting Started with Rails — Ruby on Rails Guides](https://guides.rubyonrails.org/getting_started.html)**
>
> Getting Started with RailsThis guide covers getting up and running with Ruby on Rails.After reading this guide, you will know: How to install Rails, create a new Rails application, and connect your application to a database. The general layout of a...

, but it seems incomplete for has\_many =\> :through.

Thanks,  
Andrew

---

<div class="post-metadata">

**Author:** ![acreadinglist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ccd318/32.png) [@acreadinglist](https://www.ruby-forum.com/u/acreadinglist)\
**Post date:** [February 6, 2010, 1:08pm UTC](https://www.ruby-forum.com/t/accepts-nested-attributes-for-with-has-many-through/183023/2 "2010-02-06T13:08:35Z")

</div>

have a look:

> **[\#73 Complex Forms Part 1 - RailsCasts](http://railscasts.com/episodes/73-complex-forms-part-1)**
>
> Short Ruby on Rails screencasts containing tips, tricks and tutorials. Great for both novice and experienced web developers.

> **[\#73 Complex Forms Part 1 - RailsCasts](http://railscasts.com/episodes/73-complex-forms-part-1)**
>
> Short Ruby on Rails screencasts containing tips, tricks and tutorials. Great for both novice and experienced web developers.

> **[\#73 Complex Forms Part 1 - RailsCasts](http://railscasts.com/episodes/73-complex-forms-part-1)**
>
> Short Ruby on Rails screencasts containing tips, tricks and tutorials. Great for both novice and experienced web developers.

2010/2/6 acreadinglist [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> “Ruby on Rails: Talk” group.  
> To post to this group, send email to removed\_email\_address@domain.invalid.  
> To unsubscribe from this group, send email to  
> removed\_email\_address@domain.invalid[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> .  
> For more options, visit this group at  
> [http://groups.google.com/group/rubyonrails-talk?hl=en](http://groups.google.com/group/rubyonrails-talk?hl=en).

–  
tommy xiao  
E-mail: xiaods(AT)[gmail.com](http://gmail.com)
