質問編集履歴
3
以前のエラーは消えましたが、createされないため
test
CHANGED
File without changes
|
test
CHANGED
@@ -297,3 +297,221 @@
|
|
297
297
|
= f.submit 'SEND', class: "baggage__send"
|
298
298
|
|
299
299
|
```
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
全く同じ記述の管理者用baggagesコントローラーがあり
|
306
|
+
|
307
|
+
```
|
308
|
+
|
309
|
+
class Admin::BaggagesController < ApplicationController
|
310
|
+
|
311
|
+
before_action :if_not_admin
|
312
|
+
|
313
|
+
before_action :set_baggage, only: [:edit, :update, :show, :destroy]
|
314
|
+
|
315
|
+
# before_action :move_to_index,only: [:show]
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
def index
|
320
|
+
|
321
|
+
if current_user.admin?
|
322
|
+
|
323
|
+
# @baggages = Baggage.search(params[:search])
|
324
|
+
|
325
|
+
@search = User.ransack(params[:q]) #:qは入力したクエリのq
|
326
|
+
|
327
|
+
@users = @search.result#検索した"結果"ユーザーのparams丸ごと
|
328
|
+
|
329
|
+
|
330
|
+
|
331
|
+
# @baggages = Baggage.find(params[:user_id])
|
332
|
+
|
333
|
+
|
334
|
+
|
335
|
+
end
|
336
|
+
|
337
|
+
end
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
def new
|
342
|
+
|
343
|
+
if current_user.admin?
|
344
|
+
|
345
|
+
@baggage = Baggage.new(baggage_params)
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
end
|
350
|
+
|
351
|
+
end
|
352
|
+
|
353
|
+
|
354
|
+
|
355
|
+
def create
|
356
|
+
|
357
|
+
# @baggage = current_user.baggages.build(baggage_params)
|
358
|
+
|
359
|
+
# @baggage = Baggage.new.(user_id: @user.id)
|
360
|
+
|
361
|
+
# binding.pry
|
362
|
+
|
363
|
+
@baggage = Baggage.new(baggage_params)
|
364
|
+
|
365
|
+
if @baggage.save
|
366
|
+
|
367
|
+
|
368
|
+
|
369
|
+
redirect_to pages_show_path(@baggage)
|
370
|
+
|
371
|
+
else
|
372
|
+
|
373
|
+
# render :new
|
374
|
+
|
375
|
+
render file: "admin/baggages/new."
|
376
|
+
|
377
|
+
end
|
378
|
+
|
379
|
+
end
|
380
|
+
|
381
|
+
|
382
|
+
|
383
|
+
def edit
|
384
|
+
|
385
|
+
# if current_user.admin?
|
386
|
+
|
387
|
+
# end
|
388
|
+
|
389
|
+
end
|
390
|
+
|
391
|
+
|
392
|
+
|
393
|
+
def update
|
394
|
+
|
395
|
+
if @baggage.update(baggage_params)
|
396
|
+
|
397
|
+
redirect_to pages_show_path(@baggage)
|
398
|
+
|
399
|
+
else
|
400
|
+
|
401
|
+
render :edit
|
402
|
+
|
403
|
+
end
|
404
|
+
|
405
|
+
end
|
406
|
+
|
407
|
+
|
408
|
+
|
409
|
+
def show
|
410
|
+
|
411
|
+
# binding.pry
|
412
|
+
|
413
|
+
# @baggage = Baggage.find_by(id: params[:id])
|
414
|
+
|
415
|
+
# @user = User.find_by(id: @baggage.user_id)
|
416
|
+
|
417
|
+
end
|
418
|
+
|
419
|
+
|
420
|
+
|
421
|
+
def destroy
|
422
|
+
|
423
|
+
end
|
424
|
+
|
425
|
+
|
426
|
+
|
427
|
+
|
428
|
+
|
429
|
+
|
430
|
+
|
431
|
+
private
|
432
|
+
|
433
|
+
|
434
|
+
|
435
|
+
|
436
|
+
|
437
|
+
def if_not_admin
|
438
|
+
|
439
|
+
redirect_to root_path unless current_user.admin?#管理者ユーザー以外が特定のアクションを実行しようとした場合トップページにリダイレクトされる
|
440
|
+
|
441
|
+
end
|
442
|
+
|
443
|
+
|
444
|
+
|
445
|
+
def set_baggage
|
446
|
+
|
447
|
+
@baggage = Baggage.find(params[:id])#edit, show, destroy などのアクションで使用する変数をセットします。
|
448
|
+
|
449
|
+
|
450
|
+
|
451
|
+
end
|
452
|
+
|
453
|
+
|
454
|
+
|
455
|
+
def baggage_params
|
456
|
+
|
457
|
+
params.permit(
|
458
|
+
|
459
|
+
:kind,:storage_period, :code, :user_id )#.merge(user_id: current_user.id)
|
460
|
+
|
461
|
+
end
|
462
|
+
|
463
|
+
|
464
|
+
|
465
|
+
# def move_to_index
|
466
|
+
|
467
|
+
# redirect_to action: :index unless user_signed_in? && current_user.id == @baggage.user_id
|
468
|
+
|
469
|
+
# end
|
470
|
+
|
471
|
+
|
472
|
+
|
473
|
+
|
474
|
+
|
475
|
+
end
|
476
|
+
|
477
|
+
```
|
478
|
+
|
479
|
+
と、修正したら以前のエラーは出なくなったものの、createはされず、下記のターミナルをみても、原因が掴めません
|
480
|
+
|
481
|
+
|
482
|
+
|
483
|
+
|
484
|
+
|
485
|
+
|
486
|
+
|
487
|
+
```
|
488
|
+
|
489
|
+
app/controllers/baggages_controller.rb:34:in `create'
|
490
|
+
|
491
|
+
Started POST "/baggages" for ::1 at 2020-10-27 08:18:42 +0900
|
492
|
+
|
493
|
+
Processing by BaggagesController#create as JS
|
494
|
+
|
495
|
+
Parameters: {"utf8"=>"✓", "authenticity_token"=>"r1DJfXsonsAr8fJOdEzLr7uyluXFz1uBTzK/4P++LNRUVBd8jgfp3ZNKbSlAe/I4ausFGKubcmtXmkuVhoHNfw==", "baggage"=>{"kind"=>"チルド", "storage_period"=>"7", "code"=>"111111111111", "user_id"=>"1"}, "commit"=>"SEND"}
|
496
|
+
|
497
|
+
Unpermitted parameters: :utf8, :authenticity_token, :baggage, :commit
|
498
|
+
|
499
|
+
(0.2ms) BEGIN
|
500
|
+
|
501
|
+
↳ app/controllers/baggages_controller.rb:29
|
502
|
+
|
503
|
+
(0.2ms) ROLLBACK
|
504
|
+
|
505
|
+
↳ app/controllers/baggages_controller.rb:29
|
506
|
+
|
507
|
+
Rendering baggages/new.html.haml within layouts/application
|
508
|
+
|
509
|
+
Rendered baggages/new.html.haml within layouts/application (8.1ms)
|
510
|
+
|
511
|
+
User Load (0.5ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 2 ORDER BY `users`.`id` ASC LIMIT 1
|
512
|
+
|
513
|
+
↳ app/views/layouts/application.html.haml:12
|
514
|
+
|
515
|
+
Completed 200 OK in 219ms (Views: 173.9ms | ActiveRecord: 21.2ms)
|
516
|
+
|
517
|
+
```
|
2
エラーで無いされているファイルです
test
CHANGED
File without changes
|
test
CHANGED
@@ -236,4 +236,64 @@
|
|
236
236
|
|
237
237
|
```
|
238
238
|
|
239
|
+
|
240
|
+
|
239
241
|
リダイレクト先をroot_pathにしてみましたが変化ありません
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
エラーで無いと言われていたファイルです
|
248
|
+
|
249
|
+
**app/views/admin/baggages/new.html.haml
|
250
|
+
|
251
|
+
```
|
252
|
+
|
253
|
+
.wrapper
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
.disply
|
258
|
+
|
259
|
+
= form_with model: @baggage do |f|
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
.baggage
|
264
|
+
|
265
|
+
.baggage__box
|
266
|
+
|
267
|
+
%span
|
268
|
+
|
269
|
+
荷物の種類
|
270
|
+
|
271
|
+
= f.select :kind, [["なまもの", "なまもの"], ["チルド", "チルド"], ["冷凍", "冷凍"], ["その他", "その他"]], include_blank: "選択して下さい"
|
272
|
+
|
273
|
+
.baggage__box
|
274
|
+
|
275
|
+
%span
|
276
|
+
|
277
|
+
保管期限
|
278
|
+
|
279
|
+
= f.text_field :storage_period, class: "baggage_text" , placeholder: '例)7'
|
280
|
+
|
281
|
+
%span 日
|
282
|
+
|
283
|
+
.baggage__box
|
284
|
+
|
285
|
+
%span
|
286
|
+
|
287
|
+
追跡番号
|
288
|
+
|
289
|
+
= f.text_field :code, class: "baggage_text", placeholder: '123456789012'
|
290
|
+
|
291
|
+
-# = f.hidden_field :user_id , :value => "#{user_session}"
|
292
|
+
|
293
|
+
= f.hidden_field :user_id
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
= f.submit 'SEND', class: "baggage__send"
|
298
|
+
|
299
|
+
```
|
1
行ってみたことを追記しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -235,3 +235,5 @@
|
|
235
235
|
end
|
236
236
|
|
237
237
|
```
|
238
|
+
|
239
|
+
リダイレクト先をroot_pathにしてみましたが変化ありません
|