RailsCasts Pro episodes are now free!

Learn more or hide this

LambdaRed's Profile

GitHub User: LambdaRed

Comments by

Avatar

I'm sure you found you solution by now, but if anyone else is looking around for this:

article.rb
has_many :taggings, :as => :taggable, :dependent => :destroy
has_many :tags, :through => :taggings

And since this is polymorphic these two lines would go into whatever model you wanted to be taggable.

tag.rb
has_many :taggings, :dependent => :destroy
has_many :taggables, :through => :taggings
tagging.rb
belongs_to :taggable, polymorphic: true
belongs_to :tag