0

用户可以关注另一个用户或公司。如何在一个表中保持关联,该表是对用户模型工作正常的追随者?我也想为公司使用同一张桌子。

退出代码。我正在为关注者功能使用自引用关联。

class User < ActiveRecord::Base

   has_many :followerships
   has_many :following, :through => :followerships


   has_many :inverse_followerships, :class_name => "Followership", :foreign_key => "following_id"
   has_many :inverse_following, :through => :inverse_followerships, :source => :user
end
4

1 回答 1

0

这对于关注用户和公司可能没有任何帮助,但是您看过 Michael Hartl 的Rails 教程吗?

基本上,他会引导您构建一个类似 twitter 的应用程序,包括关注其他用户和被关注。由于他的代码非常干净,因此查看此类事情的最佳实践可能会有所帮助。

第 11 章:关注用户

于 2013-09-04T00:20:31.403 回答