views:

22

answers:

1

I have posts that can be voted on by a polymorphic association. Now I am making comments votable as well. Can I share the same models and logic for this for my comments? Or do I have to make a new model relationship ?

#post.rb
has_many                      :votes, :as => :votable                          
has_many                      :voting_users,                                   
                              :through => :votes,                              
                              :source => :user 
#vote.rb
belongs_to :votable, :polymorphic => true
+3  A: 

Yes, you should be able to copy the two has_many relationships from your post model and drop them in comment.rb without a problem. Since your vote model is polymorphic, as long as you have votable_id:integer and votable_type:string in the votes table, everything should work normally.

Brett Bender
Thanks Brett ;D
Trip