質問編集履歴

2

users.ymlを追記しました

2020/05/22 14:58

投稿

pome00000
pome00000

スコア5

test CHANGED
File without changes
test CHANGED
@@ -603,3 +603,19 @@
603
603
  end
604
604
 
605
605
  end
606
+
607
+
608
+
609
+
610
+
611
+ ```yml
612
+
613
+ michael:
614
+
615
+ name: Michael Example
616
+
617
+ email: michael@example.com
618
+
619
+ password_digest: <%= User.digest('password') %>
620
+
621
+ ```

1

ご指摘いただいたuser.rbの中身を追記しました。

2020/05/22 14:58

投稿

pome00000
pome00000

スコア5

test CHANGED
File without changes
test CHANGED
@@ -559,3 +559,47 @@
559
559
 
560
560
 
561
561
  エラーがたくさん出てしまってとても驚いてしまい内容に不足点があるかもしれません…
562
+
563
+
564
+
565
+
566
+
567
+ <追記>
568
+
569
+ user.rb⇩
570
+
571
+
572
+
573
+ class User < ApplicationRecord
574
+
575
+ before_save { self.email = email.downcase }
576
+
577
+ validates :name, presence: true, length: { maximum: 50 }
578
+
579
+ VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+.[a-z]+\z/i
580
+
581
+ validates :email, presence: true, length: { maximum: 255 },
582
+
583
+ format: { with: VALID_EMAIL_REGEX },
584
+
585
+ uniqueness: true
586
+
587
+ has_secure_password
588
+
589
+ validates :password, presence: true, length: { minimum: 6 }
590
+
591
+
592
+
593
+ **#渡された文字列のハッシュ値を返す**
594
+
595
+ def User.digest(string)
596
+
597
+ cost = ActiveModel::SecurePassword.min_cost ? BCrypt::Engine::MIN_COST :
598
+
599
+ BCrypt::Engine.cost
600
+
601
+ BCrypt::Password.create(string, cost: cost)
602
+
603
+ end
604
+
605
+ end