Add tagging methods to the target class. For more information on the algorithms used surf: www.pui.ch/phred/archives/2005/04/tags-database-schemas.html

Example

class Article

   include Taggable
   ..
 end

article.tag(‘great’, ‘gmosx’, ‘nitro’) article.tags article.tag_names Article.find_with_tags(‘great’, ‘gmosx’) Article.find_with_any_tag(‘name’, ‘gmosx’)

Tag.find_by_name(‘ruby’).articles

Methods
Included Modules
Classes and Modules
Module Og::Mixin::Taggable::ClassMethods
Public Class methods
included(base)
     # File lib/og/model/taggable.rb, line 247
247:   def self.included(base)
248:     Tag.many_to_many base
249:     base.extend ClassMethods
250:     base.many_to_many Tag
251:     #--
252:     # FIXME: Og should handle this automatically.
253:     #++
254:     base.before :on_delete do
255:       tags.clear
256:     end    
257:   end
tags_to_names(the_tags, separator = Taggable.separator)

Helper.

     # File lib/og/model/taggable.rb, line 261
261:   def self.tags_to_names(the_tags, separator = Taggable.separator)
262:     if the_tags.is_a? Array
263:       names = the_tags 
264:     elsif the_tags.is_a? String
265:       names = the_tags.split(separator)
266:     end
267:     
268:     names = names.flatten.uniq.compact
269:     
270:     return names
271:   end
Public Instance methods
clear_tags()

Alias for #delete_all_tags

delete_all_tags()

Delete all tags from this taggable object.

This method is also aliased as clear_tags
     # File lib/og/model/taggable.rb, line 157
157:   def delete_all_tags
158:     for tag in tags
159:       tag.reload
160:       tag.unlink
161:     end
162:     tags.clear
163:   end
delete_tag(name)

Delete a single tag from this taggable object.

     # File lib/og/model/taggable.rb, line 149
149:   def delete_tag(name)
150:     if dtag = (tags.delete_if { |t| t.name == name }).first
151:       dtag.unlink
152:     end
153:   end
tag(the_tags, options = {})

Add a tag for this object.

This method is also aliased as tag!
     # File lib/og/model/taggable.rb, line 133
133:   def tag(the_tags, options = {})
134:     options = {
135:       :clear => true
136:     }.merge(options)
137:       
138:     delete_all_tags() if options[:clear]
139:     
140:     for name in Taggable.tags_to_names(the_tags)
141:       the_tag = Tag.find_or_create_by_name(name)
142:       the_tag.tag(self)
143:     end    
144:   end
tag!(the_tags, options = {})

Alias for #tag

tag_names()

Return the names of the tags.

     # File lib/og/model/taggable.rb, line 168
168:   def tag_names
169:     tags.collect { |t| t.name }
170:   end
tag_string(separator = ' ')

Return the tag string

     # File lib/og/model/taggable.rb, line 174
174:   def tag_string(separator = ' ')
175:     tags.collect { |t| t.name }.join(separator)    
176:   end
tag_string_linked(separator = ' ')

Return the linked tag string. Typically you will overrie this in your application.

     # File lib/og/model/taggable.rb, line 181
181:   def tag_string_linked(separator = ' ')
182:     tags.collect { |t| %|<a href="/tags/#{t.to_s_safe}">#{t.name}</a>| }.join(separator)    
183:   end
tagged_by?(tag_name)

Alias for #tagged_with?

tagged_with?(tag_name)

Checks to see if this object has been tagged with tag_name.

This method is also aliased as tagged_by?
     # File lib/og/model/taggable.rb, line 188
188:   def tagged_with?(tag_name)
189:     tag_names.include?(tag_name)
190:   end