質問編集履歴
2
users.ymlを追記しました
title
CHANGED
File without changes
|
body
CHANGED
@@ -300,4 +300,12 @@
|
|
300
300
|
BCrypt::Engine.cost
|
301
301
|
BCrypt::Password.create(string, cost: cost)
|
302
302
|
end
|
303
|
-
end
|
303
|
+
end
|
304
|
+
|
305
|
+
|
306
|
+
```yml
|
307
|
+
michael:
|
308
|
+
name: Michael Example
|
309
|
+
email: michael@example.com
|
310
|
+
password_digest: <%= User.digest('password') %>
|
311
|
+
```
|
1
ご指摘いただいたuser.rbの中身を追記しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -278,4 +278,26 @@
|
|
278
278
|
https://github.com/yasslab/sample_apps/tree/master/6_0_0/ch08
|
279
279
|
・railsチュートリアル8章で書いたコードを一度コメントアウトしても同じエラーが出ました。
|
280
280
|
|
281
|
-
エラーがたくさん出てしまってとても驚いてしまい内容に不足点があるかもしれません…
|
281
|
+
エラーがたくさん出てしまってとても驚いてしまい内容に不足点があるかもしれません…
|
282
|
+
|
283
|
+
|
284
|
+
<追記>
|
285
|
+
user.rb⇩
|
286
|
+
|
287
|
+
class User < ApplicationRecord
|
288
|
+
before_save { self.email = email.downcase }
|
289
|
+
validates :name, presence: true, length: { maximum: 50 }
|
290
|
+
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+.[a-z]+\z/i
|
291
|
+
validates :email, presence: true, length: { maximum: 255 },
|
292
|
+
format: { with: VALID_EMAIL_REGEX },
|
293
|
+
uniqueness: true
|
294
|
+
has_secure_password
|
295
|
+
validates :password, presence: true, length: { minimum: 6 }
|
296
|
+
|
297
|
+
**#渡された文字列のハッシュ値を返す**
|
298
|
+
def User.digest(string)
|
299
|
+
cost = ActiveModel::SecurePassword.min_cost ? BCrypt::Engine::MIN_COST :
|
300
|
+
BCrypt::Engine.cost
|
301
|
+
BCrypt::Password.create(string, cost: cost)
|
302
|
+
end
|
303
|
+
end
|