vendredi 2 octobre 2015

ActiveRecord::RecordNotFound in UsersController#show Couldn't find User with 'id'=1

I am following Michael Hartl's tutorial. I get the following error:

ActiveRecord::RecordNotFound in UsersController#show
Couldn't find User with 'id'=1

Extracted source (around line #155)
    record = s.execute([id], self, connection).first
    unless record
      raise RecordNotFound, "Couldn't find #{name} with '#{primary_key}'=#{id}"
    end
    record
  rescue RangeError

Already have tried bundle install and restarted the server because the initial error related to the bcrypt Gemfile (using v 3.1.7).

Running rails console and inputing User.find(1) yields no user. However, User.all in rails c does reveal that I have one user but it has an id: 2 (the very first user I made was likely deleted during prior test runs).

app/controllers/users_controller.rb

class UsersController < ApplicationController

 def show
 @user = User.find(params[:id])
 end

 def new
 end
end

app/config/routes.rb Rails.application.routes.draw do

  get 'users/new'

  root 'static_pages#home'
  get 'help' => 'static_pages#help'
  get 'about' => 'static_pages#about'
  get 'contact' => 'static_pages#contact'
  get 'signup' => 'users#new'
  resources :users

end

How can I resolve this?

Aucun commentaire:

Enregistrer un commentaire