Module: TaggableModel::TaggableInstanceMethods

Defined in:
lib/taggable_model.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) add_tag(word = nil)



86
87
88
# File 'lib/taggable_model.rb', line 86

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


99
100
101
# File 'lib/taggable_model.rb', line 99

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

- (Object) keywords

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.



106
107
108
# File 'lib/taggable_model.rb', line 106

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

- (Object) keywords=(somewords = ""))



110
111
112
113
114
115
116
# File 'lib/taggable_model.rb', line 110

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

- (Object) keywords_before_type_cast

for form_helper



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

def keywords_before_type_cast   # for form_helper
  keywords
end


95
96
97
# File 'lib/taggable_model.rb', line 95

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

- (Object) remove_tag(word = nil)



90
91
92
93
# File 'lib/taggable_model.rb', line 90

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

- (Object) tags_from_keywords



122
123
124
125
126
# File 'lib/taggable_model.rb', line 122

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