title: Rails Tutorial Chapter 11 error "uninitialized constant User::Relationships"
body: <p>I have consistently been receiving the error</p>
  
  <pre><code>   uninitialized constant User::Relationships
  </code></pre>
  
  <p>When working through chapter 11 of the rails tutorial.</p>
  
  <p>Here is the full error when I try to access the home page while logged in in my browser.</p>
  
  <pre><code>    Extracted source (around line #11):
  
  8:          &lt;/a&gt;
  9:          &lt;a href="&lt;%= followers_user_path(@user) %&gt;"&gt;
  10:         &lt;strong id="followers" class="stat"&gt;
  11:             &lt;%= @user.followers.count %&gt;
  12:         &lt;/strong&gt;
  13:         followers
  14:     &lt;/a&gt;
  </code></pre>
  
  <p>I have gone through the chapter multiple times and checked every line of code, but sometimes your eyes play tricks on you so here is the rest of the code</p>
  
  <p>users.rb</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
  attr_accessible :email, :name, :password, :password_confirmation
  has_secure_password
  
  has_many :microposts, dependent: :destroy 
  has_many :relationships, foreign_key: "follower_id", dependent: :destroy
  has_many :followed_users, through: :relationships, source: :followed 
  has_many :reverse_relationships, foreign_key: "followed_id",
                                 class_name: "Relationships",
                                 dependent:   :destroy
  has_many :followers, through: :reverse_relationships, source: :follower
  
  before_save { |user| user.email = email.downcase}
  before_save :create_remember_token
  
  validates :name, presence:true, length: { maximum: 50 }
  
  VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
  validates :email, presence: true, format: { with: VALID_EMAIL_REGEX},
                  uniqueness: { case_sensitive: false }
  validates :password, presence: true, length: { minimum: 6}
  validates :password_confirmation, presence: true
  
  def feed
    Micropost.where("user_id =?", id)
  end
  
  def following?(other_user)
    relationships.find_by_followed_id(other_user.id)
  end
  
  def follow!(other_user)
    relationships.create!(followed_id: other_user.id)
  end
  
  def unfollow!(other_user)
    relationships.find_by_followed_id(other_user.id).destroy
  end
  
  private
    def create_remember_token
      self.remember_token = SecureRandom.urlsafe_base64
    end
  
  end
  </code></pre>
  
  <p>This is the class itself</p>
  
  <pre><code>class Relationship &lt; ActiveRecord::Base
    attr_accessible :followed_id
    belongs_to :follower, class_name: "User"
    belongs_to :followed, class_name: "User"
  
    validates :follower_id, presence: true
    validates :followed_id, presence: true
  end
  </code></pre>
  
  <p>This is how it is in the tutorial... I added :follower_id back in just in case and it still didn't work.</p>
  
  <p>And I also have a relationship_controller built.</p>
  
  <pre><code>class RelationshipsController &lt; ApplicationController
  before_filter :signed_in_user
  
  def create
    @user = User.find(params[:relationship][:follower_id])
    current_user.follow!(@user)
    respond_to do |format|
      format.html { redirect_to @user }
      format.js
    end
  end
  
  def destroy
    @user = Relationship.find(params[:id]).followed
    current_user.unfollow!(@user)
    respond_to do |format|
      format.html { redirect_to @user }
      fromat.js
    end
  end
  </code></pre>
  
  <p>end</p>
  
  <p>And in routes... </p>
  
  <pre><code> resources :users do
     member do
       get :following, :followers
     end
   end
  </code></pre>
  
  <p>The page where the error is happening looks like this:</p>
  
  <pre><code>&lt;% @user ||= current_user %&gt;
  &lt;div class = "stats"&gt;
  &lt;a href ="&lt;%= following_user_path(@user)%&gt;"&gt;
      &lt;strong id="following" class="stat"&gt;
          &lt;%= @user.followed_users.count %&gt;
      &lt;/strong&gt;
      following
  &lt;/a&gt;
  &lt;a href="&lt;%= followers_user_path(@user) %&gt;"&gt;
      &lt;strong id="followers" class="stat"&gt;
          &lt;%= @user.followers.count %&gt;
      &lt;/strong&gt;
      followers
  &lt;/a&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>The first part of the code before the second  block works perfectly when I removed the second part.  It is just the "followers" relationship is not getting set up for some reason.  I played around with it in the console and it wasn't calling, whereas user.followed_users does work.  I have been playing with this for four hours, have dropped the table and rebuilt it and I can't get it to work.</p>
  
  <p>I tried looking on stack overflow before and found this:</p>
  
  <p><a href="https://stackoverflow.com/questions/5304421/ruby-error-uninitialized-constant-userrelationship">Ruby error (uninitialized constant User::Relationship)</a></p>
  
  <p>But none of the solutions there helped.  Thanks for any help!</p>