質問編集履歴

4

show.html.erbの追加

2020/12/15 00:49

投稿

gakugaku_6
gakugaku_6

スコア0

test CHANGED
File without changes
test CHANGED
@@ -301,3 +301,33 @@
301
301
  app/controllers/orders_controller.rb:11:in `create'
302
302
 
303
303
  ```
304
+
305
+ show.html.erb
306
+
307
+ ```
308
+
309
+ # 省略
310
+
311
+
312
+
313
+ <% if user_signed_in? %>
314
+
315
+ <% if current_user.id == @food.user_id %>
316
+
317
+  <%= link_to '商品の編集', edit_food_path(@food.id), method: :get, class: "food-btn" %>
318
+
319
+ <%= link_to '削除', "/foods/#{@food.id}", method: :delete, class:'food-destroy' %>
320
+
321
+ <% else %>
322
+
323
+ <%= link_to '購入する',food_orders_path(@food.id), class:"food-btn", method: :post%>
324
+
325
+ <% end %>
326
+
327
+ <% end %>
328
+
329
+
330
+
331
+ # 省略
332
+
333
+ ```

3

logの追加

2020/12/15 00:49

投稿

gakugaku_6
gakugaku_6

スコア0

test CHANGED
File without changes
test CHANGED
@@ -219,3 +219,85 @@
219
219
  <% end %>
220
220
 
221
221
  ```
222
+
223
+
224
+
225
+ log
226
+
227
+ ```
228
+
229
+ Started GET "/foods/1" for ::1 at 2020-12-13 13:28:58 +0900
230
+
231
+ Processing by FoodsController#show as HTML
232
+
233
+ Parameters: {"id"=>"1"}
234
+
235
+ Food Load (0.4ms) SELECT `foods`.* FROM `foods` WHERE `foods`.`id` = 1 LIMIT 1
236
+
237
+ ↳ app/controllers/foods_controller.rb:56:in `set_food'
238
+
239
+ Rendering foods/show.html.erb within layouts/application
240
+
241
+ User Load (0.4ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 2 ORDER BY `users`.`id` ASC LIMIT 1
242
+
243
+ ↳ app/views/shared/_header.html.erb:15
244
+
245
+ Rendered shared/_header.html.erb (Duration: 4.7ms | Allocations: 2467)
246
+
247
+ ActiveStorage::Attachment Load (0.4ms) SELECT `active_storage_attachments`.* FROM `active_storage_attachments` WHERE `active_storage_attachments`.`record_id` = 1 AND `active_storage_attachments`.`record_type` = 'Food' AND `active_storage_attachments`.`name` = 'image' LIMIT 1
248
+
249
+ ↳ app/views/foods/show.html.erb:11
250
+
251
+ ActiveStorage::Blob Load (0.3ms) SELECT `active_storage_blobs`.* FROM `active_storage_blobs` WHERE `active_storage_blobs`.`id` = 1 LIMIT 1
252
+
253
+ ↳ app/views/foods/show.html.erb:11
254
+
255
+ Rendered foods/show.html.erb within layouts/application (Duration: 9.5ms | Allocations: 4794)
256
+
257
+ [Webpacker] Everything's up-to-date. Nothing to do
258
+
259
+ Completed 200 OK in 90ms (Views: 86.0ms | ActiveRecord: 1.5ms | Allocations: 25558)
260
+
261
+
262
+
263
+
264
+
265
+ Started GET "/rails/active_storage/disk/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdDRG9JYTJWNVNTSWhOMlF4YTJGaWFHYzFOR2czWjNoMU1XRXhkM0JtT0hkNGNUUnRlUVk2QmtWVU9oQmthWE53YjNOcGRHbHZia2tpUTJsdWJHbHVaVHNnWm1sc1pXNWhiV1U5SW5SbGNtbDVZV3RwTG1wd1p5STdJR1pwYkdWdVlXMWxLajFWVkVZdE9DY25kR1Z5YVhsaGEya3VhbkJuQmpzR1ZEb1JZMjl1ZEdWdWRGOTBlWEJsU1NJUGFXMWhaMlV2YW5CbFp3WTdCbFE9IiwiZXhwIjoiMjAyMC0xMi0xM1QwNDozMTozNC43MTFaIiwicHVyIjoiYmxvYl9rZXkifX0=--aa418a0630aa9d3b3d01b135de8251b42140df17/teriyaki.jpg?content_type=image%2Fjpeg&disposition=inline%3B+filename%3D%22teriyaki.jpg%22%3B+filename%2A%3DUTF-8%27%27teriyaki.jpg" for ::1 at 2020-12-13 13:28:58 +0900
266
+
267
+ Processing by ActiveStorage::DiskController#show as JPEG
268
+
269
+ Parameters: {"content_type"=>"image/jpeg", "disposition"=>"inline; filename=\"teriyaki.jpg\"; filename*=UTF-8''teriyaki.jpg", "encoded_key"=>"eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdDRG9JYTJWNVNTSWhOMlF4YTJGaWFHYzFOR2czWjNoMU1XRXhkM0JtT0hkNGNUUnRlUVk2QmtWVU9oQmthWE53YjNOcGRHbHZia2tpUTJsdWJHbHVaVHNnWm1sc1pXNWhiV1U5SW5SbGNtbDVZV3RwTG1wd1p5STdJR1pwYkdWdVlXMWxLajFWVkVZdE9DY25kR1Z5YVhsaGEya3VhbkJuQmpzR1ZEb1JZMjl1ZEdWdWRGOTBlWEJsU1NJUGFXMWhaMlV2YW5CbFp3WTdCbFE9IiwiZXhwIjoiMjAyMC0xMi0xM1QwNDozMTozNC43MTFaIiwicHVyIjoiYmxvYl9rZXkifX0=--aa418a0630aa9d3b3d01b135de8251b42140df17", "filename"=>"teriyaki"}
270
+
271
+ Completed 304 Not Modified in 2ms (ActiveRecord: 0.0ms | Allocations: 728)
272
+
273
+
274
+
275
+
276
+
277
+ Started POST "/foods/1/orders" for ::1 at 2020-12-13 13:29:02 +0900
278
+
279
+ Processing by OrdersController#create as HTML
280
+
281
+ Parameters: {"authenticity_token"=>"VgUl7/gmHxJZtJ0Nm4uuRp+MCFNYqE3o5Q+gXG6SzQCVDwNxbLnO4BbseoNR1L738ou63i7lt6TahMmTqTRJGg==", "food_id"=>"1"}
282
+
283
+ Food Load (0.5ms) SELECT `foods`.* FROM `foods` WHERE `foods`.`id` = 1 LIMIT 1
284
+
285
+ ↳ app/controllers/orders_controller.rb:34:in `set_food'
286
+
287
+ Completed 400 Bad Request in 5ms (ActiveRecord: 0.5ms | Allocations: 1634)
288
+
289
+
290
+
291
+
292
+
293
+
294
+
295
+ ActionController::ParameterMissing (param is missing or the value is empty: address_order):
296
+
297
+
298
+
299
+ app/controllers/orders_controller.rb:24:in `order_params'
300
+
301
+ app/controllers/orders_controller.rb:11:in `create'
302
+
303
+ ```

2

不備の修正

2020/12/13 04:33

投稿

gakugaku_6
gakugaku_6

スコア0

test CHANGED
File without changes
test CHANGED
@@ -22,7 +22,7 @@
22
22
 
23
23
  def order_params
24
24
 
25
-       # ↓require(:address_order)
25
+           # ↓この部分
26
26
 
27
27
  params.require(:address_order).permit(:postal_code, :city, :street, :house_name, :phone_number).merge(user_id: current_user.id, food_id: params[:food_id])
28
28
 

1

状況の詳細

2020/12/10 05:14

投稿

gakugaku_6
gakugaku_6

スコア0

test CHANGED
File without changes
test CHANGED
@@ -22,6 +22,8 @@
22
22
 
23
23
  def order_params
24
24
 
25
+       # ↓require(:address_order)
26
+
25
27
  params.require(:address_order).permit(:postal_code, :city, :street, :house_name, :phone_number).merge(user_id: current_user.id, food_id: params[:food_id])
26
28
 
27
29
  end
@@ -32,6 +34,10 @@
32
34
 
33
35
  Googleで調べたところ、address_orderが無い又は空である。
34
36
 
37
+ ・require(:address_order)があると保存はできるがそもそも商品購入フォームへいけなくなる(param is missing or the value is empty: address_orderとエラー)
38
+
39
+ ・require(:address_order)が無いと商品購入フォームへ行けるがsubmit時に保存出来ない
40
+
35
41
 
36
42
 
37
43
  ##該当のソースコード