title: Rails self-join gives an error
body: <p>I'm having troubles getting my friending model in Rails 4 working. I set up a friendship controller and modified my User model to use a self-join as follows.</p>
  
  <p>Friendship Model:</p>
  
  <pre><code>class Friendship &lt; ActiveRecord::Base
  
      belongs_to :user
      belongs_to :friend, class_name: "User", foreign_key: "friend_id"
  
      validates_presence_of :user_id, :friend_id
  end
  </code></pre>
  
  <p>User Model:</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
    rolify
    # Include default devise modules. Others available are:
    # :confirmable, :lockable, :timeoutable and :omniauthable
    devise :invitable, :database_authenticatable, :registerable, :confirmable,
           :recoverable, :rememberable, :trackable, :validatable
  
           has_many :items
           has_many :friendships
  end
  </code></pre>
  
  <p>My UserController: </p>
  
  <pre><code>class UsersController &lt; ApplicationController
    before_action :set_user, only: [:show, :edit, :update, :destroy]
    before_filter :authenticate_user!
    load_and_authorize_resource
  
    def index
      authorize! :index, @user, message: 'Not authorized as an administrator.'
      @users = User.all
    end
  
    def update
      authorize! :update, @user, message: 'Not authorized as an administrator.'
      if @user.update_attributes(params[:user])
        redirect_to users_path, notice: "User updated."
      else
        redirect_to users_path, alert: "Unable to update user."
      end
    end
  
    def destroy
      authorize! :destroy, @user, message: 'Not authorized as an administrator.'
      user = User.find(params[:id])
      unless user == current_user
        user.destroy
        redirect_to users_path, notice: "User deleted."
      else
        redirect_to users_path, notice: "Can't delete yourself."
      end
    end
  
    private
  
  # Use callbacks to share common setup or constraints between actions.
  def set_user
    @user = User.find(params[:id])
  end
  
  # Never trust parameters from the scary internet, only allow the white list through.
  def user_params
    params.require(:user).permit( :name, :email, :role_ids, :id, :user_id )
  end
  
  
  end
  </code></pre>
  
  <p>The relevant portion of my log:</p>
  
  <p>NoMethodError - undefined method <code>friends' for nil:NilClass:
    app/views/users/index.html.erb:32:in</code>_app_views_users_index_html_erb__2019584293611114470_70229529361660'</p>
  
  <p>Unless I've missed this completely, I should be able to access a friend as @users.friends but that gives me a NoMethod Error. I've also tried accessing it as @users.friendships but I get the same error.</p>
  
  <p>I have run the migration and restarted my rails server. I don't know what I'm missing but I would sure appreciate a fresh set of eyes. I think it must be something with how I've set up the model.</p>