tag.name in show.rhtml

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)<p> 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

The code is at:

http://strawr.googlecode.com/svn/trunk/app/views/feeds/show.rhtml

Thanks,

Thufir

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 :slight_smile: ? tag.name means call the name method on tag, and the line above says
you're iterating through the tags of the feed.

Fred

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:

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 :frowning:

-Thufir

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

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

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#_<foo>.rb and so forth).