RailsCasts Pro episodes are now free!
Learn more or hide this
GitHub User: amalhotra
Quick and dirty way to even add new tags on the fly.
# Class that is taggable def tag_tokens=(ids) ids = ids.split(',') self.tag_list = Tag.get_tags_from_tokens(ids) end # tag.rb def self.get_tags_from_tokens(tokens) tags = [] ids = [] tokens.each do |token| if token =~ /<<<(.+?)>>>/ tags << token.gsub(/<<<(.+?)>>>/, $1) else ids << token end end tags.concat(Tag.where(:id => ids).map(&:name)) unless ids.empty? tags.join(",") end
Maybe a better way is to just change the behavior on the client side?
Missing this!
def self.ids_from_tokens(tokens) tokens.gsub!(/<<<(.+?)>>>/) { create!(name: $1).id } tokens.split(',') end
Got this from the source.
Quick and dirty way to even add new tags on the fly.
Maybe a better way is to just change the behavior on the client side?
Missing this!
Got this from the source.