質問編集履歴
2
誤字修正
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
obj.errors.full_messagesを加えるとブラウザをrefreshしないとmodelの作成/更新(CRUD)ができない
|
test
CHANGED
File without changes
|
1
原因が判明したため修正
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ブラウザをrefreshしないとmodelの作成/更新(CRUD)ができない
|
1
|
+
`obj.errors.full_messagesを加えるとブラウザをrefreshしないとmodelの作成/更新(CRUD)ができない
|
test
CHANGED
@@ -2,458 +2,112 @@
|
|
2
2
|
|
3
3
|
|
4
4
|
|
5
|
+
- リスト`obj.errors.full_messages`を`view`に加えたことが原因のようで`obj.errors.full_messages`を外すと通常通りにページrefreshしなくとも動作します。
|
6
|
+
|
5
|
-
`
|
7
|
+
- リスト`obj.errors.full_messages`は他のviewでも使えるように、`partial`にしてます。
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
これを解決する方法はありますでしょうか?或いは、そもそも私のコードの書き方に問題があるのでしょうか?
|
6
12
|
|
7
13
|
|
8
14
|
|
9
15
|
```ruby
|
10
16
|
|
11
|
-
##
|
17
|
+
## _errors.html.erb ->複数のmodelで共通して利用
|
12
18
|
|
13
|
-
|
19
|
+
<% if obj.errors.present? %>
|
14
20
|
|
15
|
-
|
21
|
+
<div id="errors" class="alert alert-warning text-left mb-3" role="alert">
|
16
22
|
|
17
|
-
|
23
|
+
<h3><strong>エラーがあります。</strong></h3>
|
18
24
|
|
19
|
-
|
25
|
+
<ul>
|
20
26
|
|
21
|
-
|
27
|
+
<% obj.errors.full_messages.each do |msg| %>
|
22
28
|
|
23
|
-
|
29
|
+
<li><%= msg %></li>
|
24
30
|
|
25
|
-
|
31
|
+
<% end %>
|
26
32
|
|
27
|
-
|
33
|
+
</ul>
|
28
34
|
|
29
|
-
|
35
|
+
<% end %>
|
30
36
|
|
31
|
-
# occupation :string
|
32
|
-
|
33
|
-
|
37
|
+
</div>
|
34
|
-
|
35
|
-
# created_at :datetime not null
|
36
|
-
|
37
|
-
# updated_at :datetime not null
|
38
|
-
|
39
|
-
# undisclosed :boolean default(FALSE)
|
40
|
-
|
41
|
-
#
|
42
38
|
|
43
39
|
|
44
40
|
|
45
|
-
|
41
|
+
## _form.html.erb(1例です)
|
46
42
|
|
47
|
-
|
43
|
+
|
48
44
|
|
49
|
-
has_many :lessons
|
50
|
-
|
51
|
-
|
45
|
+
<%= render "shared/errors", obj: @user %>
|
52
46
|
|
53
47
|
|
54
48
|
|
55
|
-
|
49
|
+
<div class="form-group text-left">
|
56
50
|
|
57
|
-
|
51
|
+
<%= f.label :user_name, "ユーザーネーム", class:"required" %>
|
58
52
|
|
53
|
+
<%= f.text_field :user_name, :class => "form-control", placeholder:"ユーザーネーム", required: true %>
|
59
54
|
|
55
|
+
</div>
|
60
56
|
|
61
|
-
v
|
57
|
+
<div class = "form-group text-left">
|
62
58
|
|
63
|
-
|
59
|
+
<%= f.label :family_name, "氏名" %>
|
64
60
|
|
65
|
-
v
|
61
|
+
<div class="row">
|
66
62
|
|
67
|
-
v
|
63
|
+
<div class="col-6 pr-0">
|
68
64
|
|
65
|
+
<%= f.text_field :family_name, :class => "form-control", placeholder:"氏:family name" %>
|
69
66
|
|
67
|
+
</div>
|
70
68
|
|
71
|
-
|
69
|
+
<div class="col-6 pl-0">
|
72
70
|
|
73
|
-
|
71
|
+
<%= f.text_field :given_name, :class => "form-control", placeholder:"名:first name" %>
|
74
72
|
|
73
|
+
</div>
|
75
74
|
|
75
|
+
</div>
|
76
76
|
|
77
|
-
|
77
|
+
</div>
|
78
78
|
|
79
|
+
<div class = "form-group text-left">
|
79
80
|
|
81
|
+
<%= f.label :family_name_kana, "氏名(ヨミガナ / Roma)" %>
|
80
82
|
|
81
|
-
|
83
|
+
<div class="row">
|
82
84
|
|
83
|
-
|
85
|
+
<div class="col-6 pr-0">
|
84
86
|
|
85
|
-
|
87
|
+
<%= f.text_field :family_name_kana, :class => "form-control", placeholder:"family name" %>
|
86
88
|
|
87
|
-
|
89
|
+
</div>
|
88
90
|
|
89
|
-
|
91
|
+
<div class="col-6 pl-0">
|
90
92
|
|
93
|
+
<%= f.text_field :given_name_kana, :class => "form-control", placeholder:"first name" %>
|
91
94
|
|
95
|
+
</div>
|
92
96
|
|
93
|
-
end
|
94
|
-
|
95
|
-
```
|
96
|
-
|
97
|
-
```ruby
|
98
|
-
|
99
|
-
## controller
|
100
|
-
|
101
|
-
class User::AdvisersController < User::Base
|
102
|
-
|
103
|
-
before_action :set_adviser_tags_to_gon, only: [:edit]
|
104
|
-
|
105
|
-
before_action :search_preparation
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
def index
|
110
|
-
|
111
|
-
end
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
def show
|
116
|
-
|
117
|
-
@user = User.find(params[:user_id])
|
118
|
-
|
119
|
-
if @user.adviser.nil?
|
120
|
-
|
121
|
-
redirect_to :user_root
|
122
|
-
|
123
|
-
return
|
124
|
-
|
125
|
-
else
|
126
|
-
|
127
|
-
end
|
128
|
-
|
129
|
-
end
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
def new
|
134
|
-
|
135
|
-
@adviser = Adviser.new
|
136
|
-
|
137
|
-
end
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
def edit
|
142
|
-
|
143
|
-
end
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
def create
|
148
|
-
|
149
|
-
@adviser = Adviser.new(adviser_params)
|
150
|
-
|
151
|
-
@adviser.user = current_user
|
152
|
-
|
153
|
-
if @adviser.save
|
154
|
-
|
155
|
-
redirect_to [:user_account]
|
156
|
-
|
157
|
-
else
|
158
|
-
|
159
|
-
render "new"
|
160
|
-
|
161
|
-
end
|
162
|
-
|
163
|
-
end
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
def update
|
168
|
-
|
169
|
-
@adviser = current_user.adviser
|
170
|
-
|
171
|
-
@adviser.assign_attributes(adviser_params)
|
172
|
-
|
173
|
-
if @adviser.save
|
174
|
-
|
175
|
-
redirect_to [:user_account]
|
176
|
-
|
177
|
-
else
|
178
|
-
|
179
|
-
|
97
|
+
</div>
|
180
|
-
|
181
|
-
end
|
182
|
-
|
183
|
-
end
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
def destroy
|
188
|
-
|
189
|
-
end
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
private def adviser_params
|
194
|
-
|
195
|
-
attrs = [
|
196
|
-
|
197
|
-
:gender, :gender_comment, :profile, :occupation, :birthday,
|
198
|
-
|
199
|
-
:tag_list, :genre_list, :brand_list, :magazine_list, :undisclosed,
|
200
|
-
|
201
|
-
situation_ids:[], part_ids:[]
|
202
|
-
|
203
|
-
]
|
204
|
-
|
205
|
-
params.require(:adviser).permit(attrs)
|
206
|
-
|
207
|
-
end
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
private def set_adviser_tags_to_gon
|
212
|
-
|
213
|
-
@user = current_user
|
214
|
-
|
215
|
-
@adviser = @user.adviser
|
216
|
-
|
217
|
-
gon.genre_tags = @adviser.genre_list
|
218
|
-
|
219
|
-
gon.brand_tags = @adviser.brand_list
|
220
|
-
|
221
|
-
gon.magazine_tags = @adviser.magazine_list
|
222
|
-
|
223
|
-
end
|
224
|
-
|
225
|
-
end
|
226
|
-
|
227
|
-
```
|
228
|
-
|
229
|
-
```html
|
230
|
-
|
231
|
-
## form
|
232
|
-
|
233
|
-
<div class="temporal-box-resize">
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
<%= render "shared/errors", obj: @adviser %>
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
<div class="alert alert-danger mt-1" role="alert">
|
242
|
-
|
243
|
-
記入頂きました内容は<strong>アドバイザーProfile</strong>として公開されます。
|
244
98
|
|
245
99
|
</div>
|
246
100
|
|
247
101
|
|
248
102
|
|
249
|
-
<div class = "form-group">
|
103
|
+
<div class = "form-group text-left">
|
250
104
|
|
251
|
-
<
|
105
|
+
<%= f.label :email, "e-mail", class:"required" %>
|
252
106
|
|
253
|
-
<%= f.label :occupation, "職業", class:"required" %>
|
254
|
-
|
255
|
-
<span class="text-muted"><small> *最大30文字</small></span>
|
256
|
-
|
257
|
-
</div>
|
258
|
-
|
259
|
-
<%= f.text_field :
|
107
|
+
<%= f.text_field :email, type: "email", class: "form-control", placeholder:"(例)yuu.sagawa@cuty.com", required: true %>
|
260
108
|
|
261
109
|
</div>
|
262
110
|
|
263
111
|
|
264
112
|
|
265
|
-
<div class="form-group">
|
266
|
-
|
267
|
-
<div class = "text-left">
|
268
|
-
|
269
|
-
<%= f.label :gender, "性別", class:"required" %>
|
270
|
-
|
271
|
-
</div>
|
272
|
-
|
273
|
-
<%= f.radio_button :gender, "male" %>
|
274
|
-
|
275
|
-
 男   
|
276
|
-
|
277
|
-
<%= f.radio_button :gender, "female" %>
|
278
|
-
|
279
|
-
 女   
|
280
|
-
|
281
|
-
<%= f.radio_button :gender, "lgbt" %>
|
282
|
-
|
283
|
-
 LGBT   
|
284
|
-
|
285
|
-
</div><!--row-->
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
<div class = "form-group text-left">
|
290
|
-
|
291
|
-
<%= f.label :gender_comment, "性別補足" %>
|
292
|
-
|
293
|
-
<span class="text-muted"><small> *最大100文字</small></span>
|
294
|
-
|
295
|
-
<%= f.text_area :gender_comment, class: "form-control", placeholder:"性別に関し、補足事項あればご記入ください。" %>
|
296
|
-
|
297
|
-
</div>
|
298
|
-
|
299
|
-
<div class = "form-group text-left">
|
300
|
-
|
301
|
-
<%= f.label :birthday, "生年月日" %>
|
302
|
-
|
303
|
-
<%= raw sprintf(
|
304
|
-
|
305
|
-
f.date_select(
|
306
|
-
|
307
|
-
:birthday,
|
308
|
-
|
309
|
-
use_month_numbers: true,
|
310
|
-
|
311
|
-
start_year: 1950,
|
312
|
-
|
313
|
-
end_year: (Time.now.year - 12),
|
314
|
-
|
315
|
-
default: Date.new(1995, 1, 1),
|
316
|
-
|
317
|
-
date_separator: '%s'),
|
318
|
-
|
319
|
-
' 年 ', ' 月 ') + ' 日 ' %>
|
320
|
-
|
321
|
-
<br>
|
322
|
-
|
323
|
-
<%= f.check_box :undisclosed %>
|
324
|
-
|
325
|
-
<%= f.label :undisclosed, ": 年齢非公開を希望する場合はチェックを入れてください"%>
|
326
|
-
|
327
|
-
</div>
|
328
|
-
|
329
|
-
<div class = "form-group text-left">
|
330
|
-
|
331
|
-
<%= f.label :profile, "プロフィール", class:"required" %>
|
332
|
-
|
333
|
-
<span class="text-muted"><small> *最大1,000文字</small></span>
|
334
|
-
|
335
|
-
<%= f.text_area :profile, class: "form-control", placeholder:"ご自由にご記載ください。", rows:"10" %>
|
336
|
-
|
337
|
-
</div>
|
338
|
-
|
339
|
-
<div class = "form-group">
|
340
|
-
|
341
|
-
<div class="text-left">
|
342
|
-
|
343
|
-
<%= f.label '得意なメイク(シチュエーション)' %>
|
344
|
-
|
345
|
-
<small>
|
346
|
-
|
347
|
-
(複数選択)
|
348
|
-
|
349
|
-
</small>
|
350
|
-
|
351
|
-
</div>
|
352
|
-
|
353
|
-
<div class="text-center">
|
354
|
-
|
355
|
-
<%= f.collection_check_boxes :situation_ids, Situation.all, :id, :name do |b| %>
|
356
|
-
|
357
|
-
<%= b.check_box %>
|
358
|
-
|
359
|
-
<%= b.label %> 
|
360
|
-
|
361
|
-
<% end %>
|
362
|
-
|
363
|
-
</div>
|
364
|
-
|
365
|
-
</div>
|
366
|
-
|
367
|
-
<div class = "form-group">
|
368
|
-
|
369
|
-
<div class="text-left">
|
370
|
-
|
371
|
-
<%= f.label '得意なメイク(パーツ)' %>
|
372
|
-
|
373
|
-
<small>
|
374
|
-
|
375
|
-
(複数選択)
|
376
|
-
|
377
|
-
</small>
|
378
|
-
|
379
|
-
</div>
|
380
|
-
|
381
|
-
<div class="text-center">
|
382
|
-
|
383
|
-
<%= f.collection_check_boxes :part_ids, Part.all, :id, :name do |b| %>
|
384
|
-
|
385
|
-
<%= b.check_box %>
|
386
|
-
|
387
|
-
<%= b.label %> 
|
388
|
-
|
389
|
-
<% end %>
|
390
|
-
|
391
|
-
</div>
|
392
|
-
|
393
|
-
</div>
|
394
|
-
|
395
|
-
<div class = "form-group">
|
396
|
-
|
397
|
-
<div class="text-left">
|
398
|
-
|
399
|
-
<%= f.label :genre_list, '得意なジャンル・キーワード' %>
|
400
|
-
|
401
|
-
<small>
|
402
|
-
|
403
|
-
( タグ付け:<span class="badge badge-primary">清楚</span>
|
404
|
-
|
405
|
-
<span class="badge badge-primary">派手</span> )
|
406
|
-
|
407
|
-
</small>
|
408
|
-
|
409
|
-
</div>
|
410
|
-
|
411
|
-
<ul id="genre-tags"></ul>
|
412
|
-
|
413
|
-
</div>
|
414
|
-
|
415
|
-
<div class = "form-group">
|
416
|
-
|
417
|
-
<div class="text-left">
|
418
|
-
|
419
|
-
<%= f.label :brand_list, '好きな化粧品ブランド' %>
|
420
|
-
|
421
|
-
<small>
|
422
|
-
|
423
|
-
( タグ付け:<span class="badge badge-info">Chanel</span>
|
424
|
-
|
425
|
-
<span class="badge badge-info">資生堂</span> )
|
426
|
-
|
427
|
-
</small>
|
428
|
-
|
429
|
-
</div>
|
430
|
-
|
431
|
-
<ul id="brand-tags"></ul>
|
432
|
-
|
433
|
-
</div>
|
434
|
-
|
435
|
-
<div class = "form-group">
|
436
|
-
|
437
|
-
<div class="text-left">
|
438
|
-
|
439
|
-
<%= f.label :magazine_list, '好きな雑誌' %>
|
440
|
-
|
441
|
-
<small>
|
442
|
-
|
443
|
-
( タグ付け:<span class="badge badge-success">Very</span>
|
444
|
-
|
445
|
-
<span class="badge badge-success">CanCam</span> )
|
446
|
-
|
447
|
-
</small>
|
448
|
-
|
449
|
-
</div>
|
450
|
-
|
451
|
-
<ul id="magazine-tags"></ul>
|
452
|
-
|
453
|
-
</div>
|
454
|
-
|
455
|
-
</div>
|
456
|
-
|
457
|
-
|
458
|
-
|
459
113
|
```
|