質問編集履歴

2

何度も申し訳ありません。完結はこれでよろしいのでしょうか。データベースのカラムにもnicknameは入っており、なぜvalidatesが引っかかるのかわからず、、

2020/10/25 06:09

投稿

Arale...3
Arale...3

スコア9

test CHANGED
File without changes
test CHANGED
@@ -1,5 +1,45 @@
1
1
  ```ここに言語を入力
2
2
 
3
+ ###ターミナル
4
+
5
+ An error occurred while loading ./spec/models/user_spec.rb.
6
+
7
+ Failure/Error: validates :nickname
8
+
9
+
10
+
11
+ NoMethodError:
12
+
13
+ undefined method `validates' for main:Object
14
+
15
+ # ./app/models/user.rb:11:in `block in <main>'
16
+
17
+ # ./app/models/user.rb:10:in `<main>'
18
+
19
+ # ./config/routes.rb:2:in `block in <main>'
20
+
21
+ # ./config/routes.rb:1:in `<main>'
22
+
23
+ # ./config/environment.rb:5:in `<top (required)>'
24
+
25
+ # ./spec/rails_helper.rb:4:in `require'
26
+
27
+ # ./spec/rails_helper.rb:4:in `<top (required)>'
28
+
29
+ # ./spec/models/user_spec.rb:1:in `require'
30
+
31
+ # ./spec/models/user_spec.rb:1:in `<top (required)>'
32
+
33
+ No examples found.
34
+
35
+
36
+
37
+ Finished in 0.00006 seconds (files took 2.49 seconds to load)
38
+
39
+ 0 examples, 0 failures, 1 error occurred outside of examples
40
+
41
+ ###Userモデル
42
+
3
43
  class User < ApplicationRecord
4
44
 
5
45
  # Include default devise modules. Others available are:
@@ -20,6 +60,130 @@
20
60
 
21
61
  with_options presence: true do
22
62
 
63
+ validates :nickname
64
+
65
+ validates :family_name, format: { with: /\A[ぁ-んァ-ン一-龥]+\z/, message: '全角文字を使用してください' }
66
+
67
+ validates :first_name, format: { with: /\A[ぁ-んァ-ン一-龥]+\z/, message: '全角文字を使用してください' }
68
+
69
+ validates :family_name_kana, format: { with: /\A[ァ-ヶー-]+\z/, message: "全角カタカナを使用してください" }
70
+
71
+ validates :first_name_kana, format: { with: /\A[ァ-ヶー-]+\z/, message: "全角カタカナを使用してください" }
72
+
73
+ validates :birth_day
74
+
75
+ validates :password, length: { minimum: 6 }, format: { with: /\A[a-z0-9]+\z/i, message: "英数字文字6以上"}
76
+
77
+
78
+
79
+ VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+.[a-z]+\z/i
80
+
81
+ validates :email, format: { with: VALID_EMAIL_REGEX }, uniqueness: { case_sensitive: false }
82
+
83
+ end
84
+
85
+ ```
86
+
87
+ ```ユーザーモデルのバリデーションでの記述でエラーが出る
88
+
89
+
90
+
91
+ 二日ほど悩んでいます。ご教授よろしくお願いします。
92
+
93
+
94
+
95
+ ## エラー文
96
+
97
+
98
+
99
+ SyntaxError:
100
+
101
+ /Users/yudaitaguchi/projects/furima-30611/app/models/user.rb:12: syntax error, unexpected tSYMBEG, expecting do or '{' or '('
102
+
103
+ validates :family_name, format: { with: ...
104
+
105
+ ^
106
+
107
+ /Users/yudaitaguchi/projects/furima-30611/app/models/user.rb:17: syntax error, unexpected tSYMBEG, expecting do or '{' or '('
108
+
109
+ validates :password, length: { minimum: ...
110
+
111
+
112
+
113
+
114
+
115
+ ### ターミナル
116
+
117
+ yudaitaguchi@taguchidainoMBP furima-30611 % bundle exec rspec spec/models/user_spec.rb
118
+
119
+
120
+
121
+ An error occurred while loading ./spec/models/user_spec.rb.
122
+
123
+ Failure/Error: require File.expand_path('../config/environment', __dir__)
124
+
125
+
126
+
127
+ SyntaxError:
128
+
129
+ /Users/yudaitaguchi/projects/furima-30611/app/models/user.rb:12: syntax error, unexpected tSYMBEG, expecting do or '{' or '('
130
+
131
+ validates :family_name, format: { with: ...
132
+
133
+ ^
134
+
135
+ /Users/yudaitaguchi/projects/furima-30611/app/models/user.rb:17: syntax error, unexpected tSYMBEG, expecting do or '{' or '('
136
+
137
+ validates :password, length: { minimum: ...
138
+
139
+ ^
140
+
141
+ # ./config/routes.rb:2:in `block in <main>'
142
+
143
+ # ./config/routes.rb:1:in `<main>'
144
+
145
+ # ./config/environment.rb:5:in `<top (required)>'
146
+
147
+ # ./spec/rails_helper.rb:4:in `require'
148
+
149
+ # ./spec/rails_helper.rb:4:in `<top (required)>'
150
+
151
+ # ./spec/models/user_spec.rb:1:in `require'
152
+
153
+ # ./spec/models/user_spec.rb:1:in `<top (required)>'
154
+
155
+ No examples found.
156
+
157
+
158
+
159
+ Finished in 0.00006 seconds (files took 0.93201 seconds to load)
160
+
161
+ 0 examples, 0 failures, 1 error occurred outside of examples
162
+
163
+
164
+
165
+ ### Userモデル
166
+
167
+ class User < ApplicationRecord
168
+
169
+ # Include default devise modules. Others available are:
170
+
171
+ # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
172
+
173
+ devise :database_authenticatable, :registerable,
174
+
175
+ :recoverable, :rememberable, :validatable
176
+
177
+
178
+
179
+ has_many :items
180
+
181
+ has_many :purchases
182
+
183
+ end
184
+
185
+ with_options presence: true do
186
+
23
187
  validates :nickname,
24
188
 
25
189
  validates :family_name, format: { with: /\A[ぁ-んァ-ン一-龥]+\z/, message: '全角文字を使用してください' }
@@ -42,85 +206,39 @@
42
206
 
43
207
  end
44
208
 
45
- ```ユーザーモデルのバリデーションでの記述でエラーが出る
46
-
47
-
48
-
49
- 二日ほど悩んでいます。ご教授よろしくお願いします。
50
-
51
-
52
-
53
- ## エラー文
54
-
55
-
56
-
57
- SyntaxError:
58
-
59
- /Users/yudaitaguchi/projects/furima-30611/app/models/user.rb:12: syntax error, unexpected tSYMBEG, expecting do or '{' or '('
60
-
61
- validates :family_name, format: { with: ...
62
-
63
- ^
64
-
65
- /Users/yudaitaguchi/projects/furima-30611/app/models/user.rb:17: syntax error, unexpected tSYMBEG, expecting do or '{' or '('
66
-
67
- validates :password, length: { minimum: ...
68
-
69
-
70
-
71
-
72
-
73
- ### ターミナル
74
-
75
- yudaitaguchi@taguchidainoMBP furima-30611 % bundle exec rspec spec/models/user_spec.rb
76
-
77
-
78
-
79
- An error occurred while loading ./spec/models/user_spec.rb.
80
-
81
- Failure/Error: require File.expand_path('../config/environment', __dir__)
82
-
83
-
84
-
85
- SyntaxError:
86
-
87
- /Users/yudaitaguchi/projects/furima-30611/app/models/user.rb:12: syntax error, unexpected tSYMBEG, expecting do or '{' or '('
88
-
89
- validates :family_name, format: { with: ...
90
-
91
- ^
92
-
93
- /Users/yudaitaguchi/projects/furima-30611/app/models/user.rb:17: syntax error, unexpected tSYMBEG, expecting do or '{' or '('
94
-
95
- validates :password, length: { minimum: ...
96
-
97
- ^
98
-
99
- # ./config/routes.rb:2:in `block in <main>'
100
-
101
- # ./config/routes.rb:1:in `<main>'
102
-
103
- # ./config/environment.rb:5:in `<top (required)>'
104
-
105
- # ./spec/rails_helper.rb:4:in `require'
106
-
107
- # ./spec/rails_helper.rb:4:in `<top (required)>'
108
-
109
- # ./spec/models/user_spec.rb:1:in `require'
110
-
111
- # ./spec/models/user_spec.rb:1:in `<top (required)>'
112
-
113
- No examples found.
114
-
115
-
116
-
117
- Finished in 0.00006 seconds (files took 0.93201 seconds to load)
118
-
119
- 0 examples, 0 failures, 1 error occurred outside of examples
120
-
121
-
122
-
123
- ### Userモデル
209
+
210
+
211
+ ### Factorybot
212
+
213
+ FactoryBot.define do
214
+
215
+ factory :user do
216
+
217
+ nickname {"abe"}
218
+
219
+ email {"kkk@gmail.com"}
220
+
221
+ password {"00000a"}
222
+
223
+ password_confirmation {"00000a"}
224
+
225
+ family_name {"ぜんかく"}
226
+
227
+ first_name {"ぜんかく"}
228
+
229
+ family_name_kana {"ゼンカクカナ"}
230
+
231
+ first_name_kana {"ゼンカクカナ"}
232
+
233
+ birth_day {"2020-01-01"}
234
+
235
+ end
236
+
237
+ end
238
+
239
+
240
+
241
+ ### User.rb
124
242
 
125
243
  class User < ApplicationRecord
126
244
 
@@ -164,80 +282,4 @@
164
282
 
165
283
  end
166
284
 
167
-
168
-
169
- ### Factorybot
170
-
171
- FactoryBot.define do
172
-
173
- factory :user do
174
-
175
- nickname {"abe"}
176
-
177
- email {"kkk@gmail.com"}
178
-
179
- password {"00000a"}
180
-
181
- password_confirmation {"00000a"}
182
-
183
- family_name {"ぜんかく"}
184
-
185
- first_name {"ぜんかく"}
186
-
187
- family_name_kana {"ゼンカクカナ"}
188
-
189
- first_name_kana {"ゼンカクカナ"}
190
-
191
- birth_day {"2020-01-01"}
192
-
193
- end
194
-
195
- end
196
-
197
-
198
-
199
- ### User.rb
200
-
201
- class User < ApplicationRecord
202
-
203
- # Include default devise modules. Others available are:
204
-
205
- # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
206
-
207
- devise :database_authenticatable, :registerable,
208
-
209
- :recoverable, :rememberable, :validatable
210
-
211
-
212
-
213
- has_many :items
214
-
215
- has_many :purchases
216
-
217
- end
218
-
219
- with_options presence: true do
220
-
221
- validates :nickname,
222
-
223
- validates :family_name, format: { with: /\A[ぁ-んァ-ン一-龥]+\z/, message: '全角文字を使用してください' }
224
-
225
- validates :first_name, format: { with: /\A[ぁ-んァ-ン一-龥]+\z/, message: '全角文字を使用してください' }
226
-
227
- validates :family_name_kana, format: { with: /\A[ァ-ヶー-]+\z/, message: "全角カタカナを使用してください" }
228
-
229
- validates :first_name_kana, format: { with: /\A[ァ-ヶー-]+\z/, message: "全角カタカナを使用してください" }
230
-
231
- validates :birth_day,
232
-
233
- validates :password, length: { minimum: 6 }, format: { with: /\A[a-z0-9]+\z/i, message: "英数字文字6以上"}
234
-
235
-
236
-
237
- VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+.[a-z]+\z/i
238
-
239
- validates :email, format: { with: VALID_EMAIL_REGEX }, uniqueness: { case_sensitive: false }
240
-
241
- end
242
-
243
285
  ```

1

ご指摘ありがとうございます。使い方がよくわからないものですいません。記述通りしています

2020/10/25 06:09

投稿

Arale...3
Arale...3

スコア9

test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,48 @@
1
+ ```ここに言語を入力
2
+
3
+ class User < ApplicationRecord
4
+
5
+ # Include default devise modules. Others available are:
6
+
7
+ # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
8
+
9
+ devise :database_authenticatable, :registerable,
10
+
11
+ :recoverable, :rememberable, :validatable
12
+
13
+
14
+
15
+ has_many :items
16
+
17
+ has_many :purchases
18
+
19
+ end
20
+
21
+ with_options presence: true do
22
+
23
+ validates :nickname,
24
+
25
+ validates :family_name, format: { with: /\A[ぁ-んァ-ン一-龥]+\z/, message: '全角文字を使用してください' }
26
+
27
+ validates :first_name, format: { with: /\A[ぁ-んァ-ン一-龥]+\z/, message: '全角文字を使用してください' }
28
+
29
+ validates :family_name_kana, format: { with: /\A[ァ-ヶー-]+\z/, message: "全角カタカナを使用してください" }
30
+
31
+ validates :first_name_kana, format: { with: /\A[ァ-ヶー-]+\z/, message: "全角カタカナを使用してください" }
32
+
33
+ validates :birth_day,
34
+
35
+ validates :password, length: { minimum: 6 }, format: { with: /\A[a-z0-9]+\z/i, message: "英数字文字6以上"}
36
+
37
+
38
+
39
+ VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+.[a-z]+\z/i
40
+
41
+ validates :email, format: { with: VALID_EMAIL_REGEX }, uniqueness: { case_sensitive: false }
42
+
43
+ end
44
+
1
- ユーザーモデルのバリデーションでの記述でエラーが出る
45
+ ```ユーザーモデルのバリデーションでの記述でエラーが出る
2
46
 
3
47
 
4
48