質問編集履歴
3
user\.rbを載せました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -5,6 +5,134 @@
|
|
5
5
|
Circular dependency detected while autoloading constant User
|
6
6
|
|
7
7
|
のようなエラーが発生してしまいます。これはどこが原因なんでしょう?必要ならコードを載せます。よろしくお願いいたします。
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
```
|
16
|
+
|
17
|
+
classs User < ActiveRecord::Base
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
attr_accessor :remember_token, :activation_token
|
22
|
+
|
23
|
+
before_save :downcase_email
|
24
|
+
|
25
|
+
before_create :create_activation_digest
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
validates :name, presence: true, length: { maximum: 50 }
|
30
|
+
|
31
|
+
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
|
32
|
+
|
33
|
+
validates :email, presence: true, length: { maximum: 255 },
|
34
|
+
|
35
|
+
format: { with: VALID_EMAIL_REGEX },
|
36
|
+
|
37
|
+
uniqueness: { case_sensitive: false }
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
has_secure_password
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
validates :password, presence: true, length: { minimum: 6 }, allow_nil: true
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
def User.digest(string)
|
52
|
+
|
53
|
+
cost = ActiveModel::SecurePassword.min_cost ? BCrypt::Engine::MIN_COST :
|
54
|
+
|
55
|
+
BCrypt::Engine.cost
|
56
|
+
|
57
|
+
BCrypt::Password.create(string, cost: cost)
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
def User.new_token
|
66
|
+
|
67
|
+
SecureRandom.urlsafe_base64
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
def remember
|
76
|
+
|
77
|
+
self.remember_token = User.new_token
|
78
|
+
|
79
|
+
update_attribute(:remember_digest, User.digest(remember_token))
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
def authenticated?(remember_token)
|
88
|
+
|
89
|
+
return false if remember_digest.nil?
|
90
|
+
|
91
|
+
BCrypt::Password.new(remember_digest).is_password?(remember_token)
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
def forget
|
100
|
+
|
101
|
+
update_attribute(:remember_digest, nil)
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
private
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
def downcase_email
|
112
|
+
|
113
|
+
self.email = email.downcase
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
def create_activation_digest
|
120
|
+
|
121
|
+
self.activation_token = User.new_token
|
122
|
+
|
123
|
+
self.activatoin_digest = User.digest(activation_token)
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
```
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
|
8
136
|
|
9
137
|
```
|
10
138
|
|
2
コードの編集
test
CHANGED
File without changes
|
test
CHANGED
@@ -6,7 +6,9 @@
|
|
6
6
|
|
7
7
|
のようなエラーが発生してしまいます。これはどこが原因なんでしょう?必要ならコードを載せます。よろしくお願いいたします。
|
8
8
|
|
9
|
+
```
|
10
|
+
|
9
|
-
|
11
|
+
User.create!(name: "Example User",
|
10
12
|
|
11
13
|
email: "example@railstutorial.org",
|
12
14
|
|
1
コードを載せました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,5 +1,49 @@
|
|
1
|
+
bundle exec rake db seed を実行すると、
|
2
|
+
|
1
3
|
rake aborted!
|
2
4
|
|
3
5
|
Circular dependency detected while autoloading constant User
|
4
6
|
|
5
7
|
のようなエラーが発生してしまいます。これはどこが原因なんでしょう?必要ならコードを載せます。よろしくお願いいたします。
|
8
|
+
|
9
|
+
```User.create!(name: "Example User",
|
10
|
+
|
11
|
+
email: "example@railstutorial.org",
|
12
|
+
|
13
|
+
password: "foobar",
|
14
|
+
|
15
|
+
password_confirmation: "foobar",
|
16
|
+
|
17
|
+
admin: true,
|
18
|
+
|
19
|
+
activated: true,
|
20
|
+
|
21
|
+
activated_at: Time.zone.now)
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
99.times do |n|
|
26
|
+
|
27
|
+
name = Faker::Name.name
|
28
|
+
|
29
|
+
email = "example-#{n+1}@railstutorial.org"
|
30
|
+
|
31
|
+
password = "password"
|
32
|
+
|
33
|
+
User.create!(name: name,
|
34
|
+
|
35
|
+
email: email,
|
36
|
+
|
37
|
+
password: password,
|
38
|
+
|
39
|
+
password_confirmation: password,
|
40
|
+
|
41
|
+
activated: true,
|
42
|
+
|
43
|
+
activated_at: Time.zone.now)
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
```
|