Sha256: 51aa66a620ef14beb8d9be8230cc0311d608cebe1df376e879894cc1c1cf361b
Contents?: true
Size: 917 Bytes
Versions: 4
Compression:
Stored size: 917 Bytes
Contents
module Odania module Taggable module TagModule def update_tags(prev_tags, cur_tags, context) prev_tags = prev_tags.nil? ? [] : prev_tags.split(',') cur_tags = cur_tags.split(',') if prev_tags != cur_tags # Remove old tags removed = prev_tags - cur_tags removed.each do |tag| tag = Odania::Tag.where(name: tag, site_id: self.site_id).first unless tag.nil? xref = Odania::TagXref.where(tag_id: tag.id, ref: self, context: context).first xref.destroy unless xref.nil? end end # Add new tags new_tags = cur_tags - prev_tags new_tags.each do |tag| odania_tag = Odania::Tag.where(name: tag, site_id: self.site_id).first odania_tag = Odania::Tag.create(name: tag, site_id: self.site_id) if odania_tag.nil? Odania::TagXref.create(tag_id: odania_tag.id, ref: self, context: context) end end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems