In the RoR guides, the following example of a polymorphic link is given everywhere:
class Comment < ActiveRecord::Base belongs_to :commentable, :polymorphic => true end class Post < ActiveRecord::Base has_many :comments, :as => :commentable end class Picture < ActiveRecord::Base has_many :comments, :as => :commentable end
It turns out that the posts (Post) and the pictures (Picture) have a lot of comments. And all the comments for example to some kind of picture can be obtained as
@post.comments @picture.comments
And how to organize such a link that one picture can have many comments and many posts? To be able to do such requests:
@image.posts @image.comments