# "has\_many :through" because "push\_with\_attributes" is deprecated

**URL:** <https://www.ruby-forum.com/t/has-many-through-because-push-with-attributes-is-deprecated/229141>\
**Category:** Rails\
**Created:** [January 18, 2008, 9:54am UTC](https://www.ruby-forum.com/t/has-many-through-because-push-with-attributes-is-deprecated/229141 "2008-01-18T09:54:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thufir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@Thufir](https://www.ruby-forum.com/u/Thufir)\
**Post date:** [January 18, 2008, 9:54am UTC](https://www.ruby-forum.com/t/has-many-through-because-push-with-attributes-is-deprecated/229141/1 "2008-01-18T09:54:26Z")

</div>

I want to use “has\_many :through” in line 78 because  
“push\_with\_attributes” is deprecated.

How would I go about this, please? I want to create, really, an  
instance  
of the Membership class.

thufir@arrakis ~/strawr $  
thufir@arrakis ~/strawr $ cat -n app/controllers/feeds\_controller.rb |  
tail -n 46 --verbose  
==\> standard input \<==  
69  
70 def add\_tag  
71  
72 @feed = Feed.find(params[:id])  
73 @feed.tags.push\_with\_attributes(  
74 Tag.find(params[:tag][:id]))  
75  
76 if @feed.save  
77 flash[:notice] = ‘Tag has been added!’  
78 end  
79 redirect\_to :action =\> ‘show’, :id =\> params[:id]  
80 end  
81  
82 def add\_some\_tags  
83  
84  
85 logger.info  
“_ **add\_some\_tags** _”  
86 logger.info  
“_ **add\_some\_tags** _”  
87 logger.info  
“_ **add\_some\_tags** _”  
88 #logger.info “foo: #{@my\_var}”  
89 #logger.info “my text”  
90 #@my\_var = “something”  
91  
92  
93 @feed = Feed.find(params[:id])  
94  
95 logger.info “@feed: #{@feed}”  
96  
97 @unused\_tags =  
98 Tag.find(:all) - @feed.tags  
99  
100 if @unused\_tags.any?  
101 @tags\_to\_add = @unused\_tags.select { |tag|  
102 (params[‘tag’+tag.id.to\_s][‘checked’] == ‘1’)}  
103 @tags\_to\_add.each { |tag|  
104 @feed.tags \<\< Tag.find\_or\_create\_by\_tag(params  
[:which\_tag]) unless params[:which\_tag].blank?  
105 }  
106 end  
107  
108 if @tags\_to\_add.any? and @feed.save  
109 flash[:notice] = ‘Tags have been added!’  
110 end  
111 redirect\_to :action =\> ‘show’, :id =\> @feed  
112 end  
113  
114 end  
thufir@arrakis ~/strawr $

code can be browsed in the “trunk” by clicking on:  
[http://strawr.googlecode.com/svn/trunk/](http://strawr.googlecode.com/svn/trunk/)

thanks,

Thufir

---

<div class="post-metadata">

**Author:** ![Thufir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@Thufir](https://www.ruby-forum.com/u/Thufir)\
**Post date:** [January 18, 2008, 10:00am UTC](https://www.ruby-forum.com/t/has-many-through-because-push-with-attributes-is-deprecated/229141/2 "2008-01-18T10:00:18Z")

</div>

On Fri, 18 Jan 2008 08:53:23 +0000, Thufir wrote:

> I want to use “has\_many :through” in line 78 because  
> “push\_with\_attributes” is deprecated.

Woops, I meant line 73.

thanks,

Thufir

---

<div class="post-metadata">

**Author:** ![Thufir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@Thufir](https://www.ruby-forum.com/u/Thufir)\
**Post date:** [January 23, 2008, 12:21pm UTC](https://www.ruby-forum.com/t/has-many-through-because-push-with-attributes-is-deprecated/229141/3 "2008-01-23T12:21:48Z")

</div>

It may have changed since I posted:

thufir@arrakis ~/strawr $  
thufir@arrakis ~/strawr $ cat -n app/controllers/feeds\_controller.rb |  
head -n 83 | tail -n 16  
68  
69  
70 def add\_tag  
71  
72 @feed = Feed.find(params[:id])  
73 @feed.tags.push\_with\_attributes(  
74 Tag.find(params[:tag][:id]))  
75  
76 if @feed.save  
77 flash[:notice] = ‘Tag has been added!’  
78 end  
79 redirect\_to :action =\> ‘show’, :id =\> params[:id]  
80 end  
81  
82 def add\_some\_tags  
83  
thufir@arrakis ~/strawr $

[http://code.google.com/p/strawr/source](http://code.google.com/p/strawr/source)

thanks,

Thufir
