我正在关注railscasts的163集,它使用户能够表示另一个用户是否有朋友,但那或多或少。与Rails的相互关系
我想找一个帮手来查找用户是否是他们的朋友。
获取彼此为好友的用户列表。
已发送不相互请求的用户列表。
@friends_out = Friendship.where(:user_id=>current_user.id) #users "i" want to be friends with
@friends_in = Friendship.where(:friend_id=>current_user.id) #users who want to be friend with "me"
# users who haven't added "my" id to Friendship and vice versa
# user who are my friend and i'm their friends.
我该怎么做?
谢谢。
你尝试过什么?如果有的话,请发布不起作用的代码。 – Dogbert 2011-05-12 13:58:01
我不知道如何开始,我可以检索user_id == current_user或friend_id ==当前和两者的友谊,并从朋友模型访问朋友或用户? – 2011-05-12 14:05:56
在控制台中的工作方式如预期:) f = Friendship.where(:user_id => 2).first.friend – 2011-05-12 14:10:58