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

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

Instance Method Summary collapse

Instance Method Details

#save_tagsObject



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/cms/behaviors/taggable.rb', line 51

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



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

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

#tag_list=(tag_names) ⇒ Object



46
47
48
49
# File 'lib/cms/behaviors/taggable.rb', line 46

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