Module: Tagtical::Tagger::InstanceMethods
- Defined in:
- lib/tagtical/acts_as_tagger.rb
Instance Method Summary collapse
- #is_tagger? ⇒ Boolean
-
#tag(taggable, opts = {}) ⇒ Object
Tag a taggable model with tags that are owned by the tagger.
Instance Method Details
#is_tagger? ⇒ Boolean
58 59 60 |
# File 'lib/tagtical/acts_as_tagger.rb', line 58 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)
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/tagtical/acts_as_tagger.rb', line 45 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 |