2017-07-12 93 views

回答

2

。看看Polymorphic Associations

class Comment < ApplicationRecord 
    belongs_to :commentable, polymorphic: true 
end 

class Article < ApplicationRecord 
    has_many :comments, as: :commentable 
end 

class Image < ApplicationRecord 
    has_many :comments, as: :commentable 
end 
相關問題