Skip to content

Instantly share code, notes, and snippets.

@beverlynelson
Created October 23, 2012 04:11
Show Gist options
  • Save beverlynelson/3936593 to your computer and use it in GitHub Desktop.
Save beverlynelson/3936593 to your computer and use it in GitHub Desktop.
article.rb - chuck guynn
class Article < ActiveRecord::Base
attr_accessible :title, :body, :tag_list, :image
has_many :comments
has_many :taggings
has_many :tags, :through => :taggings
has_attached_file :image
def tag_list
return self.tags.join(", ")
end
def tag_list=(tags_string)
self.taggings.destroy_all
tag_names = tags_string.split(",").collect{|s| s.strip.downcase}.uniq
tag_names.each do |tag_name|
tag = Tag.find_or_create_by_name(tag_name)
tagging = self.taggings.new
tagging.tag_id = tag.id
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment