Works in model but not in mixin


#1

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!