2010-06-09 3 views

답변

0

조금 뒤돌아 보면 다른 사람도 찾고있는 경우 this screencast도 매우 유용하다는 것을 알았습니다.

2

정확히 다형성 연관이 설계되었습니다. http://guides.rails.info/association_basics.html#polymorphic-associations

확인은 기본적으로 당신이 뭔가를 할 것이다 :

Class User < ActiveRecord::Base 
    has_many :comments 
end 

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

class Video < ActiveRecord::Base 
    has_many :comments, :as => :commentable 
end 
class Article < ActiveRecord::Base 
    has_many :comments, :as => :commentable 
end 
# ... so on 

확인 마이그레이션을 설계하는 방법에 대한 위의 링크. 이 예제에서 사용하는 imageable_ * 대신 commentable_idcommentable_type 열이 필요합니다.

관련 문제