显示current_user不遵循的所有用户

时间:2013-11-05 16:58:38

标签: ruby-on-rails activerecord ruby-on-rails-4 relationship railstutorial.org

我正在开发一个类似于Michael Hartl的Railstutorial的示例应用程序,并希望显示当前用户的所有用户。我怎么能这样做?

User.rb是:

has_many :following_relationships, class_name: "Relationship", foreign_key: :follower_id
has_many :leading_relationships, class_name: "Relationship", foreign_key: :leader_id

Relationship.rb是:

belongs_to :follower, class_name: "User"
belongs_to :leader, class_name: "User"

1 个答案:

答案 0 :(得分:0)

这会有用吗?

@followingusers =您所关注的用户所拥有的一切

@notfollowingusers = User.where(“id not in(?)”,@ followingusers.map(&:id))