| Module | ActiveRecord::Acts::Taggable::InstanceMethods |
| In: |
lib/taggable.rb
|
This method applies tags to the target object, by parsing the tags parameter into Tag object instances and adding them to the tag collection of the object. If the tag name already exists in the tags table, it just adds a relationship to the existing tag record. If it doesn’t exist, it then creates a new Tag record for it.
The tags parameter can be a String, Array or a Proc object. If it’s a String, it’s splitted using the +:separator+ specified in the options hash. If it’s an Array it is flattened and compacted. Duplicate entries will be removed as well. Tag names are also stripped of trailing and leading whitespaces. If a Proc is passed, the proc should split the string in any way it wants and return an array of strings.
The options hash has the following parameters:
+:separator+ => defines the separator (String or Regex) used to split the tags parameter and defaults to ’ ’ (space and line breaks).
+:clear+ => defines whether the existing tag collection will be cleared before applying the new tags passed. Defaults to false.
Returns an array of strings containing the tags applied to this object. If reload is true, the tags collection is reloaded.