Module: Taggable::Model::TaggableInstanceMethods

Defined in:
lib/taggable/model.rb

Instance Method Summary collapse

Instance Method Details

#add_tag(word = nil) ⇒ Object



105
106
107
# File 'lib/taggable/model.rb', line 105

def add_tag(word=nil)
  self.attached_tags << Tag.for(word) if word && !word.blank?
end


118
119
120
# File 'lib/taggable/model.rb', line 118

def closely_related
  self.attached_tags.empty? ? [] : self.class.from_all_tags(self.attached_tags) - [self]
end

#keywordsObject

in the case of pages and anything else that keywords in the same way this overrides the existing column the rest of the time it’s just another way of specifying tags.



125
126
127
# File 'lib/taggable/model.rb', line 125

def keywords 
  self.attached_tags.map {|t| t.title}.join(', ')
end

#keywords=(somewords = "") ⇒ Object



129
130
131
132
133
134
135
# File 'lib/taggable/model.rb', line 129

def keywords=(somewords="")
  if somewords.blank?
    self.attached_tags.clear
  else
    self.attached_tags = Tag.from_list(somewords)
  end
end

#keywords_before_type_castObject

for form_helper



137
138
139
# File 'lib/taggable/model.rb', line 137

def keywords_before_type_cast   # for form_helper
  keywords
end


114
115
116
# File 'lib/taggable/model.rb', line 114

def related
  self.attached_tags.empty? ? [] : self.class.from_tags(self.attached_tags) - [self]
end

#remove_tag(word = nil) ⇒ Object



109
110
111
112
# File 'lib/taggable/model.rb', line 109

def remove_tag(word=nil)
  tag = Tag.find_by_title(word) if word && !word.blank?
  self.attached_tags.delete(tag) if tag
end

#tags_from_keywordsObject



141
142
143
144
145
# File 'lib/taggable/model.rb', line 141

def tags_from_keywords
  if self.class.column_names.include?('keywords') && keys = read_attribute(:keywords)
    self.attached_tags = Tag.from_list(keys)
  end
end