title: Models associated with one another create undefined methods in Rails 5 undefined method `shoutouts' for #<User:0x007fd825472cf0>
body: <p>Was using Michael Harti's <a href="https://www.railstutorial.org/book/user_microposts" rel="nofollow noreferrer">Ruby on Rails Tutorial</a> and when following it I get an undefined method between two models. I have renamed the models and tried playing around a lot with it but all attempts end up with undefined methods or an uninitialized constant.</p>
  
  <p>Shout Out controller</p>
  
  <pre><code>class ShoutOutController &lt; ApplicationController
  
  def show
      @user = User.find(params[:id])
  end
  
  def create
      @shout_out = current_user.shout_out.build(shout_out_params)
      if @shout_out.save
          flash[:success] = "Shout Out Created"
          redirect_to root_url
      else
          render user
      end
  end
  
  def destroy
  end
  
  private
  
  def shout_out_params
      params.require(:shout_out).permit(:content)
  end
  end
  </code></pre>
  
  <p>User Controller</p>
  
  <pre><code>class UsersController &lt; ApplicationController
    def index
      @users = User.paginate(page: params[:page])
    end
    def new
      @user = User.new
    end
  
    def show
      @user = User.find(params[:id])
      @shoutouts = @user.shout_outs.paginate(page: params[:page])
      @shoutouts.user = User.find(params[:id]).name
    end
  
    def create
      @user = User.new(user_params)
      if @user.save
        log_in @user
        flash[:success] = "Welcome!"
        redirect_to @user
      else
        render 'new'
      end
    end
  
    def edit
      @user = User.find(params[:id])
    end
  
    def update
      @user = User.find(params[:id])
      if @user.update_attributes(user_params)
        #handles successful update of account info
        flash[:success] = "Updated Profile Info"
        redirect_to @user
     else
        render 'edit'
     end
   end
  
  private
  
    def user_params
      params.require(:user).permit(:name, :email, :password,           :password_confirmation)
    end
  end
  </code></pre>
  
  <p>user model</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
    attr_accessor :remember_token 
    # :activation_token
    has_many :scrimmages
    has_many :ShoutOuts, dependent: :destroy
    has_many :friendships
    has_many :direct_messages, :through =&gt; :friendships
    before_save :downcase_email
    # before_create :create_activation_digest
    validates :name, presence: true, length: { maximum: 50 }
    VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
    validates :email, presence: true, length: { maximum: 255 }, format: {with: VALID_EMAIL_REGEX}, uniqueness: { case_sensitive: false}
    has_secure_password
    validates :password, presence: true, length: { minimum: 6 }
    def User.digest(string)
      cost = ActiveModel::SecurePassword.min_cost ? BCrypt::Engine::MIN_COST : BCrypt::Engine.cost
      BCrypt::Password.create(string, cost: cost)
    end
  
    #returns a random token for remember function
    def User.new_token
      SecureRandom.urlsafe_base64
    end
  
    # Remembers a user in the database for use in persistent sessions
    def remember
      self.remember_token = User.new_token
      update_attribute(:remember_digest, User.digest(remember_token))
    end
  
    #returns true if token matches the digest
    def authenticated?(remember_token)
      return false if remember_digest.nil?
      BCrypt::Password.new(remember_digest).is_password?(remember_token)
    end
    #forgets the user
    def forget
      update_attribute(:remember_digest, nil)
    end
  
    private
  
    # converts emails to downcase
    def downcase_email
      self.email = email.downcase
    end
    #creates and assigns activation token and digest
    def create_activation_digest
      self.activation_token = User.new_token
      self.activation_digest = User.digest(activation_token)
    end
  end
  </code></pre>
  
  <p>micropost model</p>
  
  <pre><code>class ShoutOut &lt; ApplicationRecord
    belongs_to :user
    default_scope -&gt; { order(created_at: :desc)}
    validates :user_id, presence: true
    validates :content, presence: true, length: {maximum: 140}
  end
  </code></pre>
  
  <p>view partial</p>
  
  <pre><code>&lt;li id="shoutout-&lt;%= ShoutOut.id %&gt;"&gt;
  &lt;%= link_to gravatar_for(ShoutOut.user, size: 50), ShoutOut.user %&gt;
  &lt;span class="user"&gt;&lt;%= link_to ShoutOut.user.name, ShoutOut.user %&gt;&lt;/span&gt;
  &lt;span class="content"&gt;&lt;%= ShoutOut.content %&gt;&lt;/span&gt;
  &lt;span class="timestamp"&gt;
      Posted &lt;%= time_ago_in_words(shout_out.created_at) %&gt; ago.
  &lt;/span&gt;
  </code></pre>
  
  <p></li></p>
  
  <p>routes file</p>
  
  <pre><code>Rails.application.routes.draw do
  
    # root to: 'users#new'
    # these routes are for showing users a login form, logging them in, and logging them out.
     get '/login' =&gt; 'sessions#new'
     post '/login' =&gt; 'sessions#create'
     get '/logout' =&gt; 'sessions#destroy'
  
    get '/signup' =&gt; 'users#new'
    post '/users' =&gt; 'users#create'
    post '/users/id/edit' =&gt; 'users#edit'
  
    resources :users
    resources :account_activations, only: [:edit]
    root to: 'landing#index'
  end
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/rZUbO.png" rel="nofollow noreferrer">Error Message Screenshot</a>-</p>