add_tag method errors

Forums > Book - Chapter 10 > add_tag method errors

Login to post a new topic

Author Message
jjkiesch
Member since 22 Jul 23:52
0 posts

I kept getting “undefined method ’+’” when trying to add tags to the photos. for some reason it doesn’t like the line:
@photo.tag_list += ’,’ + params:tag
however @photo.tag_list.add(params:tag) will work in place of this.

alan
Member since 26 Jun 23:06
0 posts

Just looking at this – it looks like the tagging library has gone through some updates… I’ll add a page describing what I’ve found, but in the meantime, your fix works, as does
@photo.tag_list.names << params[:tag][:name]

Herb Taylor
Member since 05 Aug 04:13
0 posts

Alan -
I saw the note:
vendor/plugins/acts_as_taggable_on_steroids/CHANGELOG:* Use scoping instead of TagCountsExtension [Michael Schuerig]

kevox
Member since 11 Jul 11:49
0 posts

I had to use ’@photo.tag_list.names << params:tag’ because when I just used :tag, I was getting a comment added to the tag along the lines of Map!WashHandsWithIndifference or something like that…
Now to trouble shoot the delete function. It is deleting the tag—however it doesn’t update the page.

kevox
Member since 11 Jul 11:49
0 posts

grr…
a feature of this forum editor is that it is hiding the ‘colon’ ‘name’ that I was placing after ‘colon’ ‘tag’

alan
Member since 26 Jun 23:06
0 posts

Try putting your code inside <code></code> tags.

wlockhart
Member since 13 Jul 09:22
0 posts
Hi All,
Even after downloading the latest version (dated November 23, 2007) of the source code from Google Code [ http://code.google.com/p/railscoders-net/downloads/list ] the ‘add a tag’ code still wasn’t working.
I eventually managed to get it to work by changing the file ‘app/controllers/user_photos_controller.rb’ as follows:
def add_tag @photo = @logged_in_user.photos.find(params[:id]) # changed to reflect latest version of acts_as_taggable_on_steroids @photo.tag_list.add(params[:tag][:name]) if @photo.save @new_tag = @photo.reload.tags.find_by_name params[:tag][:name] else render :nothing => true end end
In particular, changing the following line:
@photo.tag_list.add(params[:tag][:name])
Hope this helps someone out there.
Kind Regards
Walter
kaplotnik
Member since 02 Dec 07:23
0 posts
Or, more simply:
@photo.tag_list << params[:tag][:name]
kaplotnik
Member since 02 Dec 07:23
0 posts

I went with this add_tag code (hoping pre tags
preserve newlines, I don’t know this textilize
stuff):

      do_update = false
      if (tag_name = params[:tag][:name].strip).blank?
        # Ignore empty tags
      elsif @photo.tag_list.index(tag_name)
        # It's already there
      else
        @photo.tag_list << tag_name
        if @photo.save
          @new_tag = @photo.reload.tags.find_by_name(tag_name)
          do_update = true
        end
      end
      if !do_update
        render :nothing => true
      end