Rails Tutorial の Chapter 6 (日本語訳) を進めています。
コンソールを見るとユーザーが作成されているようなのですが、
Couldn't find User with id=1
とエラーを吐いてしまう理由をご教授頂きたいです。
user_controller.rb
class UsersController < ApplicationController
def show
@user = User.find(params[:id])
end
def new
end
end
user.rb
class User < ActiveRecord::Base
before_save { self.email = email.downcase }
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 }
has_secure_password
validates :password, length: { minimum: 6 }
end
rails console --sandboxの結果
2.0.0-p481 :007 > User.find(1)
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]]
=> #<User id: 2, name: "testuesr", email: "[email protected]", created_at: "2015-01-01 13:28:14", updated_at: "2015-01-01 13:28:14", password_digest: "$2a$10$XHiVgRQlirrbx8oehDGii.Ko/Vi8NHaud920gniw6RFy...">
user table
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :name
t.string :email
t.timestamps
end
end
end
schema.rb
ActiveRecord::Schema.define(version: 20150101022243) do
create_table "users", force: true do |t|
t.string "name"
t.string "email"
t.datetime "created_at"
t.datetime "updated_at"
t.string "password_digest"
end
add_index "users", ["email"], name: "index_users_on_email", unique: true
end