Module: Cms::Behaviors::Taggable::InstanceMethods

Defined in:
lib/cms/behaviors/taggable.rb

Instance Method Summary collapse

Instance Method Details

#save_tagsObject



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/cms/behaviors/taggable.rb', line 42

def save_tags
  tag_list_tags = tag_list.to_s.split(self.class.tag_separator).map{|t| Tag.find_or_create_by_name(t.strip) }
  taggings.each do |tg|
    if tag_list_tags.include?(tg.tag)
      tag_list_tags.delete(tg.tag)
    else
      tg.destroy
    end
  end
  tag_list_tags.each{|t| taggings.create(:tag => t, :taggable => self) }
  self.tag_list = nil
end

#tag_listObject



35
36
37
# File 'lib/cms/behaviors/taggable.rb', line 35

def tag_list
  @tag_list ||= tags.reload.map(&:name).join(self.class.tag_separator)
end

#tag_list=(tag_names) ⇒ Object



38
39
40
41
# File 'lib/cms/behaviors/taggable.rb', line 38

def tag_list=(tag_names)
  changed_attributes["tag_list"] = tag_list unless @tag_list == tag_names
  @tag_list = tag_names
end