I have a Comment model obviously to make comments. I have also a Person and Family class and I want to make comments on bother a person and a family. How can I set this up. I want to use the same generic comments table for all the comments on both person and family model. I can''t figure it out, I can set up comments for either a Person or a Family one at a time but not both. Comment person_id Class Person has_many :comments How can I make comments work on the Family model too? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
You want to make comment a polymophic association e.g. on your person and family model you have: has_many :comments, :as => :attachable then on the comment class you have: belongs_to :attachable, :polymorphic => true and in your table for comments you have: integer :attachable_id string :attachable_type text :comment Best, Daniel On Mar 8, 8:46 pm, eggie5 <egg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have a Comment model obviously to make comments. I have also a > Person and Family class and I want to make comments on bother a person > and a family. How can I set this up. I want to use the same generic > comments table for all the comments on both person and family model. I > can''t figure it out, I can set up comments for either a Person or a > Family one at a time but not both. > > Comment > person_id > > Class Person > has_many :comments > > How can I make comments work on the Family model too?-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
thanks you! polymorphic association it''s called you say. It works now. On Mar 9, 12:08 pm, Daniel Guettler <daniel.guett...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> You want to make comment a polymophic association > e.g. on your person and family model you have: > > has_many :comments, :as => :attachable > > then on the comment class you have: > > belongs_to :attachable, :polymorphic => true > > and in your table for comments you have: > > integer :attachable_id > string :attachable_type > text :comment > > Best, Daniel > > On Mar 8, 8:46 pm, eggie5 <egg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > I have a Comment model obviously to make comments. I have also a > > Person and Family class and I want to make comments on bother a person > > and a family. How can I set this up. I want to use the same generic > > comments table for all the comments on both person and family model. I > > can''t figure it out, I can set up comments for either a Person or a > > Family one at a time but not both. > > > Comment > > person_id > > > Class Person > > has_many :comments > > > How can I make comments work on the Family model too?-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Mon, Mar 8, 2010 at 10:20 PM, eggie5 <eggie5-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> thanks you! polymorphic association it''s called you say. It works > now. >You might want to have a look at the acts_as_commentable plugin http://github.com/jackdempsey/acts_as_commentable It expands on this idea, but uses commentable rather than attachable as the association name, which I think makes a bit more sense, and is less likely to collide if you decide that one or more of the models which can have comments can also have uploaded files as attachments. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.