假设我有一个User
和Post
一个Comment
模型,它允许用户对帖子发表评论。我已经建立了一个多态关系,如下所示:
class User < ActiveRecord::Base
has_many :comments
end
class GroupRun < ActiveRecord::Base
has_many :comments, :as => :commentable
end
class Comment < ActiveRecord::Base
belongs_to :commentable, polymorphic: true
belongs_to :user
end
我现在想允许一个用户评论另一个用户,但我遇到了困难。我原以为我可以做一些类似的事情,has_many :notes, :as_commentable
但这不起作用。
有什么建议吗?