views:

36

answers:

2

hi,

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 => user), :method => :post %>
      <div class="clear"></div>
    </p>
  </div>
<% end %>
</div>

Controller .............

@users = User.all
A: 

See the approved answer to my similar question.

SingleShot
A: 
<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>
John