title: Rails undefined method count
body: <p>I am trying to check that an address isn't being used before I delete it. My code is as follows:</p>
  
  <pre><code>def destroy
          @address = current_user.addresses.find_by_id(params[:id])
          redirect_to user_addresses_path(current_user) if @address.nil?
  
          if Organisation.find_by_address_id(params[:id]).count == 0 &amp;&amp; Event.find_by_address_id(params[:id]).count == 0
              @address.destroy
              redirect_to user_addresses_path(current_user)
          else
              flash[:error] = "Cannot delete address because it is being used"
              redirect_to user_addresses_path(current_user)
          end
      end
  </code></pre>
  
  <p>however, this gives me an error:</p>
  
  <pre><code>undefined method `count' for nil:NilClass
  </code></pre>
  
  <p>What am I doing wrong?</p>