In the below code i want to Restrict display loggedin user in list of users
index
<div id="users">
<% for user in @users %>
<div class="user">
<p>
<strong><%=h user.username %></strong>
<%= link_to "Add Friend", friendships_path(:friend_id =&g开发者_StackOverflowt; user), :method => :post %>
<div class="clear"></div>
</p>
</div>
<% end %>
</div>
Controller .............
@users = User.all
<div id="users">
<% for user in @users %>
<% unless user.id == current_user.id # ← DO THIS :-) %>
<div class="user">
<p>
<strong><%=h user.username %></strong>
<%= link_to "Add Friend", friendships_path(:friend_id => user), :method => :post %>
<div class="clear"></div>
</p>
</div>
<% end %>
<% end %>
</div>
精彩评论