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

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

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

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.

B Gates

Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around

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