My Example:
class Category < ActiveRecord::Base
has_many :tags, :as => :tagable, :dependent => :destroy
def tag_string
str = ''
tags.each_with_index do |t, i|
str+= i > 0 ? ', ' : ''
str+= t.tag
end
str
end
def tag_string=(str)
tags.delete_all
Tag.parse_string(str).each { |t| tags.build(:tag => t.strip) }
end
end
How would you optimize this tag_string field? I don't want to delete all the tags every time I would like to just update them. Is there a better way to parse string with tags? I do not want use a plugin! Thx.