I am setting up a tagging system using polymorphism and it works about
half the way I would expect it to. One thing in my app that can be
tagged is blogs. I am able to tag them and it works as I expect when I
save the blog and when I call blog.tags it returns the list of tags
associated with that blog. The thing that does not work is when I am
trying to display a list of all the blogs for a certain tag. For
tag = Tag.find(1)
tag.blogs ## => returns nil
Here is my setup:
class Tag < ActiveRecord::Base
class Tagging < ActiveRecord::Base
belongs_to :taggable, :polymorphic => true
class Blog < ActiveRecord::Base
has_many :taggings, :as => :taggable
has_many :tags, :through => :taggings
##when I save a blog in my controller, I do this to assign a tag to it
blog = Blog.find(1)
tagging = Tagging.new(:tag_id=>tag_id)
tagging.taggable = blog
I have tried experimenting with all kinds of things in the Tag model
(ex: has_many :blogs, :through =>:taggings), but nothing seems to work.
What am I missing? Maybe I am misunderstanding how polymorphism works
or maybe there is a better way to set this up in general.
Thanks in advance!