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



122
123
124
# File 'lib/taggable/model.rb', line 122

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

#keywords=(somewords = "") ⇒ Object



126
127
128
129
130
131
132
# File 'lib/taggable/model.rb', line 126

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



134
135
136
# File 'lib/taggable/model.rb', line 134

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



138
139
140
141
142
# File 'lib/taggable/model.rb', line 138

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