开发者

Restrict logged in user in list

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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜