title: ActiveRecord::RecordNotFound in ConversationsController#index -- Couldn't find User with 'id'=
body: <p>I'm receiving the following error when attempting to access the /conversations URL in my Ruby on Rails app:</p>
  
  <pre><code>ActiveRecord::RecordNotFound in ConversationsController#index
  
  Couldn't find User with 'id'=
  
  Extracted source (around line #154):
  152    record = s.execute([id], self, connection).first
  153    unless record
  154      raise RecordNotFound, "Couldn't find #{name} with '#{primary_key}'=#{id}"
  155    end
  156    record
  157  rescue RangeError
  
  Rails.root: /home/ubuntu/workspace
  
  app/controllers/conversations_controller.rb:25:in `correct_user'
  </code></pre>
  
  <p>What does this error indicate? I've already got the resource defined in my routes.rb file:</p>
  
  <pre><code>resources :conversations, only: [:index, :show, :destroy]
  </code></pre>
  
  <p>And the link in _header.html.erb used to access the /conversations URL is:</p>
  
  <pre><code>&lt;li&gt;
    &lt;%= link_to conversations_path do %&gt;
      &lt;span class="glyphicon glyphicon-envelope"&gt;&lt;/span&gt;&amp;nbsp;Messages
    &lt;% end %&gt;
  &lt;/li&gt;
  </code></pre>
  
  <h2>Additional Information:</h2>
  
  <p>-<strong>Conversations Controller</strong>:</p>
  
  <pre><code>class ConversationsController &lt; ApplicationController
    before_action :logged_in_user, only: [:index, :show, :destroy]
    before_action :correct_user, only: [:index, :show, :destroy]
    before_action :get_mailbox
    before_action :get_conversation, except: [:index]
  
    def show
    end
  
    def index
      @conversations = @mailbox.inbox.paginate(page: params[:page], per_page: 10)
    end
  
    private
  
    def get_mailbox
      @mailbox ||= current_user.mailbox
    end
  
    def get_conversation
      @conversation ||= @mailbox.conversations.find(params[:id])
    end
  
    def correct_user
      @user = User.find(params[:id])
      redirect_to(root_url) unless current_user?(@user)
    end
  end
  </code></pre>
  
  <p>-<strong>User Model</strong>:</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
    acts_as_messageable
    has_many :listings, dependent: :destroy
    attr_accessor :remember_token, :activation_token, :reset_token
    before_save   :downcase_email
    before_create :create_activation_digest
    validates :first_name,  presence: true, length: { maximum: 25 }
    validates :last_name, presence: true, length: { maximum: 50 }
    validates :username, presence: true, uniqueness: true, length: {maximum: 50 }
    VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(\.[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, length: { minimum: 6 }, allow_blank: true
  
  
    class &lt;&lt; self
      # Returns the hash digest of the given string.
      def 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.
      def new_token
        SecureRandom.urlsafe_base64
      end
    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 the given token matches the digest.
  def authenticated?(attribute, token)
    digest = send("#{attribute}_digest")
    return false if digest.nil?
    BCrypt::Password.new(digest).is_password?(token)
  end
  
  # Forgets a user.
  def forget
    update_attribute(:remember_digest, nil)
  end
  
  # Activates an account.
  def activate
    update_attribute(:activated,  true)
    update_attribute(:activated_at, Time.zone.now)
  end
  
  # Sends activation email.
  def send_activation_email
    UserMailer.account_activation(self).deliver_now
  end
  
  # Sets the password reset attributes.
  def create_reset_digest
    self.reset_token = User.new_token
    update_attribute(:reset_digest, User.digest(reset_token))
    update_attribute(:reset_sent_at, Time.zone.now)
  end
  
  # Sends password reset email.
  def send_password_reset_email
    UserMailer.password_reset(self).deliver_now
  end
  
  # Returns true if a password reset has expired.
  def password_reset_expired?
    reset_sent_at &lt; 2.hours.ago
  end
  
  
  private
  
    # Converts email to all lower-case.
    def downcase_email
      self.email = email.downcase
    end
  
    # Creates and assigns the 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>