Module: ActsAsTaggableOn::Tagger::InstanceMethods

Defined in:
lib/acts_as_taggable_on/acts_as_tagger.rb

Instance Method Summary collapse

Instance Method Details

#is_tagger?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/acts_as_taggable_on/acts_as_tagger.rb', line 56

def is_tagger?
  self.class.is_tagger?
end

#tag(taggable, opts = {}) ⇒ Object

Tag a taggable model with tags that are owned by the tagger.

Example:

@user.tag(@photo, :with => "paris, normandy", :on => :locations)

Parameters:

  • taggable

    The object that will be tagged

  • options (Hash)

    An hash with options. Available options are:

    • :with - The tags that you want to

    • :on - The context on which you want to tag



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/acts_as_taggable_on/acts_as_tagger.rb', line 43

def tag(taggable, opts={})
  opts.reverse_merge!(:force => true)

  return false unless taggable.respond_to?(:is_taggable?) && taggable.is_taggable?

  raise "You need to specify a tag context using :on"                unless opts.has_key?(:on)
  raise "You need to specify some tags using :with"                  unless opts.has_key?(:with)
  raise "No context :#{opts[:on]} defined in #{taggable.class.to_s}" unless (opts[:force] || taggable.tag_types.include?(opts[:on]))

  taggable.set_owner_tag_list_on(self, opts[:on].to_s, opts[:with])
  taggable.save
end