質問編集履歴

1

テスト結果の追記

2020/02/23 01:17

投稿

no1knows
no1knows

スコア3365

test CHANGED
File without changes
test CHANGED
@@ -47,3 +47,185 @@
47
47
 
48
48
 
49
49
  どうぞよろしくお願いいたします。
50
+
51
+
52
+
53
+
54
+
55
+ ##追記(2020/2/23)
56
+
57
+
58
+
59
+ Controllerの設定を
60
+
61
+
62
+
63
+ A.scaffoldで作成したままの状態
64
+
65
+ B.scaffoldで作成し、redirect先をtests_urlにした場合
66
+
67
+
68
+
69
+
70
+
71
+ ---
72
+
73
+ 【Aの設定】
74
+
75
+ formの設定     : `remote: true`
76
+
77
+ Controllerの設定  : `redirect_to @test`(#showへのリダイレクト)
78
+
79
+ show.js.erbの有無 : 無し
80
+
81
+
82
+
83
+ ---
84
+
85
+ 【Aの結果】
86
+
87
+ `TestController#Create`メソッドがjsで実行されている。(remote:true)
88
+
89
+ (通常であれば`show.js.erb`が実行されるはずだが)・・・・`※ここが勘違い※`
90
+
91
+ `TestController#showがHTML`で実行されている
92
+
93
+
94
+
95
+ ---
96
+
97
+ 【Aの実行結果】
98
+
99
+ ```
100
+
101
+ Started POST "/tests" for 127.0.0.1 at 2020-02-23 09:02:07 +0900
102
+
103
+ Processing by TestsController#create as JS
104
+
105
+ Parameters: {"authenticity_token"=>"sE3rv3ba5Fn8pSF/UBVBTNZn3SNQeh/Tf2a/jzh1FZCLTRbzwbrbhbp7IXuli5vKJBh9cg49oC3Q7T1DhkS90w==", "test"=>{"name"=>"iiiiiiiiiiii"}, "commit"=>"Create Test"}
106
+
107
+  (0.1ms) begin transaction
108
+
109
+ ↳ app/controllers/tests_controller.rb:30:in `block in create'
110
+
111
+ Test Create (0.4ms) INSERT INTO "tests" ("name", "created_at", "updated_at") VALUES (?, ?, ?) [["name", "iiiiiiiiiiii"], ["created_at", "2020-02-23 00:02:07.433656"], ["updated_at", "2020-02-23 00:02:07.433656"]]
112
+
113
+ ↳ app/controllers/tests_controller.rb:30:in `block in create'
114
+
115
+  (6.6ms) commit transaction
116
+
117
+ ↳ app/controllers/tests_controller.rb:30:in `block in create'
118
+
119
+ Redirected to http://localhost:3000/tests/3
120
+
121
+ Completed 200 OK in 11ms (ActiveRecord: 7.1ms | Allocations: 2812)
122
+
123
+
124
+
125
+
126
+
127
+ Started GET "/tests/3" for 127.0.0.1 at 2020-02-23 09:02:07 +0900
128
+
129
+ Processing by TestsController#show as HTML
130
+
131
+ Parameters: {"id"=>"3"}
132
+
133
+ Test Load (0.1ms) SELECT "tests".* FROM "tests" WHERE "tests"."id" = ? LIMIT ? [["id", 3], ["LIMIT", 1]]
134
+
135
+ ↳ app/controllers/tests_controller.rb:67:in `set_test'
136
+
137
+ Rendering tests/show.html.erb within layouts/application
138
+
139
+ Rendered tests/show.html.erb within layouts/application (Duration: 0.2ms | Allocations: 80)
140
+
141
+ [Webpacker] Everything's up-to-date. Nothing to do
142
+
143
+ Completed 200 OK in 11ms (Views: 8.8ms | ActiveRecord: 0.1ms | Allocations: 5400)
144
+
145
+
146
+
147
+ ```
148
+
149
+ ![イメージ説明](ab8df884e088ba5c1c0d9a07f87d9399.png)
150
+
151
+
152
+
153
+ ---
154
+
155
+ 【Bの設定】
156
+
157
+ formの設定     : `remote: true`
158
+
159
+ Controllerの設定  : `redirect_to tests_url`(#indexへのリダイレクト)
160
+
161
+ show.js.erbの有無 : 無し
162
+
163
+
164
+
165
+ ---
166
+
167
+ 【Bの結果】
168
+
169
+ `TestController#Create`メソッドがjsで実行されている。(remote:true)
170
+
171
+ (通常であれば`show.js.erb`が実行されるはずだが)・・・・`※ここが勘違い※`
172
+
173
+ `TestController#indexがHTML`で実行されている
174
+
175
+
176
+
177
+ ---
178
+
179
+ 【Bの実行結果】
180
+
181
+ ```
182
+
183
+ Started POST "/tests" for 127.0.0.1 at 2020-02-23 09:08:31 +0900
184
+
185
+ Processing by TestsController#create as JS
186
+
187
+ Parameters: {"authenticity_token"=>"ftWx2hZ5cqRIljWtE1IrhkaR3rD0iiE8LRopR7IIQW9F1UyWoRlNeA5INanmzPEAtO5+4arNnsKCkauLDDnpLA==", "test"=>{"name"=>"eeeeeeeeeeee"}, "commit"=>"Create Test"}
188
+
189
+  (0.1ms) begin transaction
190
+
191
+ ↳ app/controllers/tests_controller.rb:30:in `block in create'
192
+
193
+ Test Create (0.6ms) INSERT INTO "tests" ("name", "created_at", "updated_at") VALUES (?, ?, ?) [["name", "eeeeeeeeeeee"], ["created_at", "2020-02-23 00:08:31.398580"], ["updated_at", "2020-02-23 00:08:31.398580"]]
194
+
195
+ ↳ app/controllers/tests_controller.rb:30:in `block in create'
196
+
197
+  (1.1ms) commit transaction
198
+
199
+ ↳ app/controllers/tests_controller.rb:30:in `block in create'
200
+
201
+ Redirected to http://localhost:3000/tests
202
+
203
+ Completed 200 OK in 10ms (ActiveRecord: 1.8ms | Allocations: 3017)
204
+
205
+
206
+
207
+
208
+
209
+ Started GET "/tests" for 127.0.0.1 at 2020-02-23 09:08:31 +0900
210
+
211
+ Processing by TestsController#index as HTML
212
+
213
+ Rendering tests/index.html.erb within layouts/application
214
+
215
+ Test Load (0.2ms) SELECT "tests".* FROM "tests"
216
+
217
+ ↳ app/views/tests/index.html.erb:14
218
+
219
+ Rendered tests/index.html.erb within layouts/application (Duration: 4.9ms | Allocations: 1101)
220
+
221
+ [Webpacker] Everything's up-to-date. Nothing to do
222
+
223
+ Completed 200 OK in 37ms (Views: 34.9ms | ActiveRecord: 0.2ms | Allocations: 5930)
224
+
225
+ ```
226
+
227
+
228
+
229
+
230
+
231
+ ![![イメージ説明](a8ce1ac301b96d147c99229ba220a0e1.png)]