I'm doing an add friend function, in the add friend page, I want to dis play all the users except the current user and the user's friends, followed by an "add" button. But I can only display all users either without current user or the user's friends. Here's my code in user model:
scope :all_except, ->(user) { where.not(id: user) && where.not(id: user.friends)}
Here's the user controller:
@users = User.all_except(current_user)
Here's the view:
<% for user in @users %>
<div class="user">
<p>
<strong><%=h user.name %></strong>
<%= link_to "Add Friend", friendships_path(:friend_id => user), :method => :post %>
<div class="clear"></div>
</p>
</div>
<% end %>
By doing this, the user's friends won't display on the page, but current user's name still there.. Can someone help? Thanks!
I tried to change the code, if I use
scope :all_except, ->(user) { where.not(id: user) && where.not(id: user.friends)}
where.not(id: user) doesn't work, and if I use
scope :all_except, ->(user) {where.not(id: user.friends) && where.not(id: user)}
where.not(id: user.friends) doesn't work