# Tag.name in show.rhtml

**URL:** <https://www.ruby-forum.com/t/tag-name-in-show-rhtml/126213>\
**Category:** Rails\
**Created:** [January 16, 2008, 10:59am UTC](https://www.ruby-forum.com/t/tag-name-in-show-rhtml/126213 "2008-01-16T10:59:29Z")\
**Posts on this page:** 6\
**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 16, 2008, 10:59am UTC](https://www.ruby-forum.com/t/tag-name-in-show-rhtml/126213/1 "2008-01-16T10:59:29Z")

</div>

There’s some cut-and-paste involved from previous, sorta working  
versions. I’m looking at line #29, and don’t understand it.

What does tag.name mean? The current Tag object? the name field for  
that object? Something else?

I’m getting the following error:

NoMethodError in Feeds#show

Showing app/views/feeds/show.rhtml where line #29 raised:

undefined method `name’ for #\<Tag:0xb7179e4c @attributes={“tag”=\>“tag  
one”, “id”=\>“1”}\>

Extracted source (around line #29):

26: (None)

27: \<% else %\>  
28: \<% for tag in @feed.tags %\>  
29: \<%= tag.name %\>&nbsp;  
30: \<%= link\_to ‘Remove’, { :action =\> ‘remove\_tag’,  
31: :id =\> @feed, :which\_tag =\> tag.id },  
32: :confirm =\> ‘Are you sure?’, :post =\> true %\>

[http://localhost:3000/feeds/show/1](http://localhost:3000/feeds/show/1)

The code is at:

[http://strawr.googlecode.com/svn/trunk/app/views/feeds/show.rhtml](http://strawr.googlecode.com/svn/trunk/app/views/feeds/show.rhtml)

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 16, 2008, 11:18am UTC](https://www.ruby-forum.com/t/tag-name-in-show-rhtml/126213/2 "2008-01-16T11:18:49Z")

</div>

On 16 Jan 2008, at 09:58, Thufir wrote:

> There’s some cut-and-paste involved from previous, sorta working  
> versions. I’m looking at line #29, and don’t understand it.
> 
> What does tag.name mean? The current Tag object? the name field for  
> that object? Something else?  
> Didn’t you write this to begin with 🙂 ?  
> tag.name means call the name method on tag, and the line above says  
> you’re iterating through the tags of the feed.

Fred

---

<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 16, 2008, 11:47am UTC](https://www.ruby-forum.com/t/tag-name-in-show-rhtml/126213/3 "2008-01-16T11:47:50Z")

</div>

Hi,

tag object doesn’t have attribute called name and it doesn’t have name  
method so you must be getting error you might replace tag.name with  
tag.tag

Thufir wrote:

> There’s some cut-and-paste involved from previous, sorta working  
> versions. I’m looking at line #29, and don’t understand it.
> 
> What does tag.name mean? The current Tag object? the name field for  
> that object? Something else?
> 
> I’m getting the following error:
> 
> NoMethodError in Feeds#show
> 
> Showing app/views/feeds/show.rhtml where line #29 raised:
> 
> undefined method `name’ for #\<Tag:0xb7179e4c @attributes={“tag”=\>“tag  
> one”, “id”=\>“1”}\>
> 
> Extracted source (around line #29):
> 
> 26: (None)
> 
> 27: \<% else %\>  
> 28: \<% for tag in @feed.tags %\>  
> 29: \<%= tag.name %\>&nbsp;  
> 30: \<%= link\_to ‘Remove’, { :action =\> ‘remove\_tag’,  
> 31: :id =\> @feed, :which\_tag =\> tag.id },  
> 32: :confirm =\> ‘Are you sure?’, :post =\> true %\>
> 
> [http://localhost:3000/feeds/show/1](http://localhost:3000/feeds/show/1)
> 
> The code is at:
> 
> [http://strawr.googlecode.com/svn/trunk/app/views/feeds/show.rhtml](http://strawr.googlecode.com/svn/trunk/app/views/feeds/show.rhtml)
> 
> 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 16, 2008, 8:16pm UTC](https://www.ruby-forum.com/t/tag-name-in-show-rhtml/126213/4 "2008-01-16T20:16:20Z")

</div>

On Wed, 16 Jan 2008 10:17:39 +0000, Frederick C. wrote:

> Didn’t you write this to begin with ? tag.name means call the name  
> method on tag, and the line above says you’re iterating through the tags  
> of the feed.
> 
> Fred

Well, there was copy/paste from a dummies book (which, of course, was  
deprecated) combined with the fact that I’ve gone back and forth with  
subversion revisions due to mucking up a naming convention…

I wish that I’d simply written the view, but that probably wasn’t the  
case ☹

-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 16, 2008, 8:29pm UTC](https://www.ruby-forum.com/t/tag-name-in-show-rhtml/126213/5 "2008-01-16T20:29:17Z")

</div>

On Wed, 16 Jan 2008 11:47:50 +0100, Rita Amritkar wrote:

> tag object doesn’t have attribute called name and it doesn’t have name  
> method so you must be getting error you might replace tag.name with  
> tag.tag

Yes, this now displays everything correctly, in that I can see which  
tags  
have been associated with a specific feed. That view for the  
has\_many\_through is working.

However, I would like to add CRUD functionality:

thufir@arrakis ~/strawr $  
thufir@arrakis ~/strawr $ tail app/controllers/feeds\_controller.rb -n 20

def add\_some\_tags  
@feed = Feed.find(params[:id])  
@unused\_tags =  
Tag.find(:all) - @feed.tags

if @unused\_tags.any?  
@tags\_to\_add = @unused\_tags.select { |tag|  
(@params[‘tag’+tag.id.to\_s][‘checked’] == ‘1’)}  
@tags\_to\_add.each { |tag|  
@feed.tags \<\< Tag.find\_or\_create\_by\_tag(params[:which\_tag])}  
end

if @tags\_to\_add.any? and @feed.save  
flash[:notice] = ‘Tags have been added!’  
end  
redirect\_to :action =\> ‘show’, :id =\> @feed  
end

end  
thufir@arrakis ~/strawr $

In the show I need to add a form to call this method?

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 16, 2008, 8:42pm UTC](https://www.ruby-forum.com/t/tag-name-in-show-rhtml/126213/6 "2008-01-16T20:42:49Z")

</div>

On Wed, 16 Jan 2008 19:28:12 +0000, Thufir wrote:

> > tag object doesn’t have attribute called name and it doesn’t have name  
> > method so you must be getting error you might replace tag.name with  
> > tag.tag
> 
> Yes, this now displays everything correctly, in that I can see which  
> tags have been associated with a specific feed. That view for the  
> has\_many\_through is working.

I forgot that I had installed a plug-in. Ok, my show does now display  
the “add tag” button (but only if there are tags not associated with  
that  
feed.) However, clicking on the button results in:

ActiveRecord::HasManyThroughCantAssociateNewRecords in  
FeedsController#add\_some\_tags

Cannot associate new records through ‘Feed#memberships’ on ‘#’. Both  
records must have an id in order to create the has\_many :through record  
associating them.

RAILS\_ROOT: ./script/…/config/…

The feeds/show.rhtml is at

[http://strawr.googlecode.com/svn/trunk/app/views/feeds/show.rhtml](http://strawr.googlecode.com/svn/trunk/app/views/feeds/show.rhtml)

I fixed the naming conventions; the model’s look good; the streamlined  
plugin has now given a “remove” CRUD interface, which is nice, and  
works.

Is it because I’m using deprecated code in the controller, perhaps?

All data was entered during the migration (from db/migrate/00#\_.rb  
and so forth).
