我正在關注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