title: Rails: how to display all pending friend requests?
body: <p>I'm working on my first Rails project and I have a small problem. I'd really appreciate any help. 
  I want to display all pending friend requests for a current user using each iterator. My controller:</p>
  
  <pre><code>class FriendRequestsController &lt; ApplicationController
  before_action :set_friend_request, except: [:index, :new, :create]
  
  def index
    @incoming = FriendRequest.where(friend: current_user)
    @outgoing = current_user.friend_requests
  end
  
  def new
    @friend_request = FriendRequest.new
  end
  
  def create
    friend = User.find(params[:friend_id])
    @friend_request = current_user.friend_requests.new(friend: friend)
    if @friend_request.save
      redirect_back(fallback_location: root_path), status: :created, location: @friend_request
    else
      render json: @friend_request.errors, status: :unprocessable_entity
    end
  end
  </code></pre>
  
  <p>When I try something like a code below, it kinda works, the conditional statement works as it should, but I know it's a terrible way to make it work, so I'd like to use @incoming since it's defined.</p>
  
  <pre><code>&lt;% if FriendRequest.where(friend: current_user).present? %&gt;
     &lt;% ?.each do |request| %&gt;
         &lt;li&gt;&lt;%= ? %&gt;&lt;/li&gt;
     &lt;% end %&gt;
  &lt;% else %&gt;
      You don't have any friend requests
  &lt;% end %&gt;
  </code></pre>
  
  <p>But when I try something like:</p>
  
  <pre><code>&lt;% if @incoming.present? %&gt;
  </code></pre>
  
  <p>The conditional statement doesn't work properly and there's 'You don't have any friend requests', even though the current user has a pending friend request.
  I don't exactly get how everything works in RoR yet, so I'd be thankful for an explanation.</p>