Rails 3を使用して友情モデルを実装しました。ユーザーが新しい友達を追加できるようにしたいのですが...見た目からすると、2つのforループが必要だと思います... 1つはすべてのユーザーをループし、もう1つはそのユーザーがすでに友達であるかどうかを確認しています...しかし、2つのforループを使用すると、期待した結果が得られず、現在のユーザーの友達であるユーザーの電子メールが印刷され、アドレスが取得されます複数回印刷されました(ループ内で印刷しているため、2番目のforループのため)..この問題を回避する他の方法はありますか????
code:
this is my view file:
<center>Bragger's list<center><br/>
<p>
<% for user in User.all %>
<% if current_user.email!= user.email %>
<% for friend in current_user.friends %>
<% if friend.email!=user.email %>
<p>
<%= user.email %> <%= link_to 'Add as Friend' , friendships_path(:friend_id => user), :method => :post %>
</p>
<br/>
<%end%>
<%end%>
<%end%>
<%end%>