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

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

Instance Method Summary collapse

Instance Method Details

#save_tagsObject



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

def save_tags
  tag_list_tags = tag_list.to_s.split(self.class.tag_separator).map{|t| Cms::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



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

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

#tag_list=(tag_names) ⇒ Object



40
41
42
43
# File 'lib/cms/behaviors/taggable.rb', line 40

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