質問編集履歴

1

save!付け加えてエラー画面を表示させた

2021/12/09 00:59

投稿

iggy-
iggy-

スコア2

test CHANGED
File without changes
test CHANGED
@@ -14,41 +14,87 @@
14
14
 
15
15
  ストロングパラメーターでIDをマージさせているのですが、保存させれなくて困っています
16
16
 
17
+
18
+
19
+ コメントをいただき、修正させていただきました。
20
+
21
+
22
+
23
+ PoopsControllerに
24
+
25
+ @poop.save!
26
+
27
+ と付け足すことでエラーの内容が
28
+
29
+ ActiveRecord::RecordInvalid in PoopsController#create
30
+
31
+ Validation failed: Humans must exist
32
+
33
+ となりました。
34
+
35
+
36
+
17
37
  お忙しいと思いますがぜひご教授お願いします
18
38
 
19
39
 
20
40
 
41
+
42
+
21
43
  ### 発生している問題・エラーメッセージ
22
44
 
23
45
 
24
46
 
25
47
  ```
26
48
 
27
- Started POST "/humans/15/poops" for ::1 at 2021-12-08 16:50:45 +0900
28
-
29
- Processing by PoopsController#create as HTML
30
-
31
- Parameters: {"authenticity_token"=>"9XYS7o1tuQQHhGDofDesU6oz65r/vVar2WgwiTo32rnNlqxIsM76WQEF+9vGOmc/9SLXtnCG12Z/t72imFMwAw==", "poop"=>{"state_id"=>"2", "weight_id"=>"2", "detail"=>"", "start_time(1i)"=>"2021", "start_time(2i)"=>"12", "start_time(3i)"=>"8", "start_time(4i)"=>"07", "start_time(5i)"=>"50"}, "commit"=>"投稿する", "human_id"=>"15"}
32
-
33
- User Load (0.5ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 ORDER BY `users`.`id` ASC LIMIT 1
34
-
35
- app/controllers/poops_controller.rb:20:in `poop_params'
36
-
37
- (0.2ms) BEGIN
38
-
39
- app/controllers/poops_controller.rb:12:in `create'
40
-
41
- User Load (1.3ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1
42
-
43
- ↳ app/controllers/poops_controller.rb:12:in `create'
44
-
45
- (0.2ms) ROLLBACK
46
-
47
- ↳ app/controllers/poops_controller.rb:12:in `create'
48
-
49
- Redirected to http://localhost:3000/
50
-
51
- Completed 302 Found in 10ms (ActiveRecord: 2.1ms | Allocations: 5174)
49
+ ActiveRecord::RecordInvalid in PoopsController#create
50
+
51
+ Validation failed: Humans must exist
52
+
53
+ Extracted source (around line #13):
54
+
55
+ 11 def create
56
+
57
+ 12 @poop = Poop.create(poop_params)
58
+
59
+ 13 @poop.save!
60
+
61
+ 14 redirect_to root_path
62
+
63
+ 15 end
64
+
65
+ 16
66
+
67
+
68
+
69
+ Request
70
+
71
+ Parameters:
72
+
73
+
74
+
75
+ {"authenticity_token"=>"BOGqp4VSXR+R00Y2RIVBBbiThd2ghuAXV++5C6Q9DOC1LXAzxCMwm7vfBlO+vBXvwlMvVm9pPyMzPIHn5vWW9A==",
76
+
77
+ "poop"=>{"state_id"=>"2", "weight_id"=>"2", "detail"=>"", "start_time(1i)"=>"2021", "start_time(2i)"=>"12", "start_time(3i)"=>"9", "start_time(4i)"=>"00", "start_time(5i)"=>"25"},
78
+
79
+ "commit"=>"投稿する",
80
+
81
+ "human_id"=>"19"}
82
+
83
+
84
+
85
+ Toggle session dump
86
+
87
+ Toggle env dump
88
+
89
+
90
+
91
+ Response
92
+
93
+ Headers:
94
+
95
+
96
+
97
+ None
52
98
 
53
99
 
54
100
 
@@ -86,6 +132,8 @@
86
132
 
87
133
  @poop = Poop.create(poop_params)
88
134
 
135
+ @poop.save!
136
+
89
137
  redirect_to root_path
90
138
 
91
139
  end