Re: Creating a comments system for multiple types of

It sounds like you want a polymorphic association -

class Party < ActiveRecord::Base
has_many :comments, :as => :commentable
end

class BlogEntry < ActiveRecord::Base
has_many :comments, :as => :commentable
end

class Comment < ActiveRecord::Base
belongs_to :commentable, :polymorphic => true
end

then include columns ‘commentable_id’ and
‘commentable_type’ in the comments table, and
ActiveRecord will do lookups based on both the foreign
key and type.

Cheers,
B Gates


Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs