Forum: Ruby on Rails Works in model but not in mixin

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Brittain (Guest)
on 2006-05-19 05:44
Disclaimer: RoR newbie.  Using the acts_as_taggable plugin.

As an exercise I wanted to switch from the destructive TAG_WITH method
to adding tags while preserving the existing ones. On the surface this
seemed easy enough and eventually I got it working. However, the
following method:

  def add_tags(list)
    Tag.transaction do
      Tag.parse(list).each do |name|
        if acts_as_taggable_options[:from]
          send(acts_as_taggable_options[:from]).tags.find_or_create_by_name(name).on(self)
        else
          Tag.find_or_create_by_name(name).on_unique(self)
        end
      end
    end
  end

Only works if placed in my model (that has the acts_as_taggable helper)
or in a controller. If I place it in the acts_as_taggable.rb instance
methods it doesn't work.  Even though it's nearly identical to the
existing TAG_WITH method (see below):

        # Destructive tagging
        def tag_with(list)
          Tag.transaction do
            taggings.destroy_all

            Tag.parse(list).each do |name|
              if acts_as_taggable_options[:from]
                send(acts_as_taggable_options[:from]).tags.find_or_create_by_name(name).on(self)
              else
                Tag.find_or_create_by_name(name).on(self)
              end
            end
          end
        end


Thanks in advance, I really need an answer on this!
This topic is locked and can not be replied to.