Kudaka-KouyanoMacBook-ea:sample_app kudaka$ rails console --sandboxRunning via Spring preloader in process 32783
Loading development environment in sandbox (Rails 6.0.3)
Any modifications you make will be rolled back on exit
irb(main):001:0> user = User.find_by(email: "michael@example.com")
(0.2ms) begin transaction
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."email" = ? LIMIT ? [["email", "michael@example.com"], ["LIMIT", 1]]
=> #<User id: 1, name: "Michael Hartl", email: "michael@example.com", created_at: "2020-10-13 07:40:23", updated_at: "2020-10-13 07:40:23", password_digest: [FILTERED]>
irb(main):002:0> user.name
=> "Michael Hartl"
irb(main):003:0> user.name = "kkkk"
=> "kkkk"
irb(main):004:0> user.save
(0.1ms) SAVEPOINT active_record_1
User Exists? (0.1ms) SELECT 1 AS one FROM "users" WHERE "users"."email" = ? AND "users"."id" != ? LIMIT ? [["email", "michael@example.com"], ["id", 1], ["LIMIT", 1]]
(0.1ms) ROLLBACK TO SAVEPOINT active_record_1
=> false
・状態
6-3-4「ユーザーの認証と作成」の演習をやっている。
ユーザーを検索して、user変数に渡した後、user.nameの値を変更しようとした。ところが、これが変更できない!
尚、実行はコマンドでDBに影響を与えないようにしている。
・今回の目的
なぜできないのか、メッセージを読み解きながら、理由を探してみる
・実際のコード