title: how can I display all users except current user and current_user's friends in ruby on rails
body: <p>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:</p>
  
  <pre><code>scope :all_except, -&gt;(user) { where.not(id: user) &amp;&amp; where.not(id: user.friends)}
  </code></pre>
  
  <p>Here's the user controller:</p>
  
  <pre><code>@users = User.all_except(current_user)
  </code></pre>
  
  <p>Here's the view:</p>
  
  <pre><code>&lt;% for user in @users %&gt;
      &lt;div class="user"&gt;
        &lt;p&gt;
          &lt;strong&gt;&lt;%=h user.name %&gt;&lt;/strong&gt;
          &lt;%= link_to "Add Friend", friendships_path(:friend_id =&gt; user), :method =&gt; :post %&gt;
        &lt;div class="clear"&gt;&lt;/div&gt;
        &lt;/p&gt;
      &lt;/div&gt;
   &lt;% end %&gt;
  </code></pre>
  
  <p>By doing this, the user's friends won't display on the page, but current user's name still there..
  Can someone help? Thanks! </p>
  
  <p>I tried to change the code, if I use </p>
  
  <pre><code>scope :all_except, -&gt;(user) { where.not(id: user) &amp;&amp; where.not(id: user.friends)}
  </code></pre>
  
  <p>where.not(id: user) doesn't work, and if I use</p>
  
  <pre><code>scope :all_except, -&gt;(user) {where.not(id: user.friends) &amp;&amp; where.not(id: user)}
  </code></pre>
  
  <p>where.not(id: user.friends) doesn't work</p>