質問編集履歴

3

paramsのメッセージを上部においた

2020/03/13 07:58

投稿

pontarou3
pontarou3

スコア18

test CHANGED
File without changes
test CHANGED
@@ -14,6 +14,8 @@
14
14
 
15
15
 
16
16
 
17
+
18
+
17
19
  #【解決したいこと】画像の投稿だけDBに保存されません
18
20
 
19
21
 
@@ -36,7 +38,41 @@
36
38
 
37
39
 
38
40
 
39
- #現状鑑み仮説をみました
41
+ #paramsのメッセージについ
42
+
43
+ ```
44
+
45
+ 42: private
46
+
47
+ 43:
48
+
49
+ 44: def post_params
50
+
51
+ 45: params.require(:post).permit(:title, :content, images_attributes: [:src]).merge(user_id: current_user.id)
52
+
53
+ 46: byebug
54
+
55
+ => 47: end
56
+
57
+ 48:
58
+
59
+ 49: def set_post
60
+
61
+ 50: @post = Post.find(params[:id])
62
+
63
+ 51: end
64
+
65
+ (byebug) params
66
+
67
+ <ActionController::Parameters {"utf8"=>"✓", "authenticity_token"=>"avP5DeA8ZSPhaUMkOvPmvW1rF7ML5bptV+cb6PMs3O5pcsBXzvHZtTVzWo0iWPC5crB/actaEN/AquKCzZY9ZA==", "post"=><ActionController::Parameters {"images_attributes"=>{"0"=>{"src"=>#<ActionDispatch::Http::UploadedFile:0x00007ff3b20f7438 @tempfile=#<Tempfile:/var/folders/ww/kfxy7w0565x8jj51gtp67gmr0000gn/T/RackMultipart20200312-43216-1o11cr3.png>, @original_filename="スクリーンショット 2020-03-04 16.04.20.png", @content_type="image/png", @headers="Content-Disposition: form-data; name=\"post[images_attributes][0][src]\"; filename=\"\xE3\x82\xB9\xE3\x82\xAF\xE3\x83\xAA\xE3\x83\xBC\xE3\x83\xB3\xE3\x82\xB7\xE3\x83\xA7\xE3\x83\x83\xE3\x83\x88 2020-03-04 16.04.20.png\"\r\nContent-Type: image/png\r\n">}}, "title"=>"1234", "content"=>"5677"} permitted: false>, "commit"=>"Save", "controller"=>"posts", "action"=>"create"} permitted: false>
68
+
69
+ ```
70
+
71
+ paramsまではデータが運ばれていると思いました。
72
+
73
+
74
+
75
+ #現状の疑わしい点の整理
40
76
 
41
77
 
42
78
 
@@ -120,39 +156,11 @@
120
156
 
121
157
  ```
122
158
 
123
- ↑paramsの値が返ってきました。下記のようにタミナル表示されいます。
124
-
125
-
126
-
127
- ```
128
-
129
- 42: private
130
-
131
- 43:
132
-
133
- 44: def post_params
134
-
135
- 45: params.require(:post).permit(:title, :content, images_attributes: [:src]).merge(user_id: current_user.id)
136
-
137
- 46: byebug
138
-
139
- => 47: end
140
-
141
- 48:
142
-
143
- 49: def set_post
144
-
145
- 50: @post = Post.find(params[:id])
146
-
147
- 51: end
148
-
149
- (byebug) params
150
-
151
- <ActionController::Parameters {"utf8"=>"✓", "authenticity_token"=>"avP5DeA8ZSPhaUMkOvPmvW1rF7ML5bptV+cb6PMs3O5pcsBXzvHZtTVzWo0iWPC5crB/actaEN/AquKCzZY9ZA==", "post"=><ActionController::Parameters {"images_attributes"=>{"0"=>{"src"=>#<ActionDispatch::Http::UploadedFile:0x00007ff3b20f7438 @tempfile=#<Tempfile:/var/folders/ww/kfxy7w0565x8jj51gtp67gmr0000gn/T/RackMultipart20200312-43216-1o11cr3.png>, @original_filename="スクリーンショット 2020-03-04 16.04.20.png", @content_type="image/png", @headers="Content-Disposition: form-data; name=\"post[images_attributes][0][src]\"; filename=\"\xE3\x82\xB9\xE3\x82\xAF\xE3\x83\xAA\xE3\x83\xBC\xE3\x83\xB3\xE3\x82\xB7\xE3\x83\xA7\xE3\x83\x83\xE3\x83\x88 2020-03-04 16.04.20.png\"\r\nContent-Type: image/png\r\n">}}, "title"=>"1234", "content"=>"5677"} permitted: false>, "commit"=>"Save", "controller"=>"posts", "action"=>"create"} permitted: false>
152
-
153
- ```
154
-
155
- paramsまではデータが運ばれていると思いました。
159
+ この記述では、paramsの値が返ってきました(上paramsメッセついに記載済み)
160
+
161
+
162
+
163
+
156
164
 
157
165
 
158
166
 

2

参考にしたURLを追加しました

2020/03/13 07:58

投稿

pontarou3
pontarou3

スコア18

test CHANGED
File without changes
test CHANGED
@@ -654,6 +654,8 @@
654
654
 
655
655
  ](https://qiita.com/daisuke19840125/items/64c9fd2bc0cf6f6f7e4d)
656
656
 
657
+ [[学習用]Rails5:CarrierWaveで画像投稿+rmagickでサムネイル保存+画像名ランダム化](https://qiita.com/matcham/items/488ad5e94673c33bb545)
658
+
657
659
 
658
660
 
659
661
 

1

みずらい部分の修正

2020/03/12 17:18

投稿

pontarou3
pontarou3

スコア18

test CHANGED
File without changes
test CHANGED
@@ -430,6 +430,90 @@
430
430
 
431
431
 
432
432
 
433
+ new.html.erb
434
+
435
+
436
+
437
+ ```
438
+
439
+ <div>
440
+
441
+ <div class = "col-md-4 offset-md-4">
442
+
443
+ <h2 class = "text-center">new post</h2>
444
+
445
+ <%= render partial: "form" %>
446
+
447
+ </div>
448
+
449
+ <div class = "col-md-4 offset-4">
450
+
451
+ <%= link_to 'トップ', root_path %>
452
+
453
+ </div>
454
+
455
+ </div>
456
+
457
+ ```
458
+
459
+
460
+
461
+ index.html.erb
462
+
463
+
464
+
465
+ ```
466
+
467
+ <%= render partial: "devise/shared/header" %>
468
+
469
+
470
+
471
+ <%# 会員登録、ログイン%>
472
+
473
+ <main role="main">
474
+
475
+ <section class="jumbotron text-center">
476
+
477
+ <div class="container">
478
+
479
+ <h3>ワンペタノート</h3>
480
+
481
+ <p class="lead text-muted">画像も投稿できる掲示板です</p>
482
+
483
+ <p>
484
+
485
+ <% if user_signed_in? %>
486
+
487
+ <%= link_to "新規投稿", new_post_path, class: 'btn btn-primary my-2' %>
488
+
489
+ <%= link_to "ログアウト", destroy_user_session_path, method: :delete, class: 'btn btn-primary my-2' %>
490
+
491
+ <% else %>
492
+
493
+ <%= link_to "新規登録", new_user_registration_path, class: 'btn btn-primary my-2' %>
494
+
495
+ <%= link_to "ログイン", new_user_session_path, class: 'btn btn-primary my-2' %>
496
+
497
+ <% end %>
498
+
499
+ </p>
500
+
501
+ </div>
502
+
503
+ </section>
504
+
505
+
506
+
507
+ <%= render partial: 'post', collection: @posts %>
508
+
509
+ <%= render :partial => "devise/shared/footer" %>
510
+
511
+ ```
512
+
513
+
514
+
515
+ ③コントローラー
516
+
433
517
  post_controller.rb
434
518
 
435
519
 
@@ -544,85 +628,7 @@
544
628
 
545
629
 
546
630
 
547
- new.html.erb
631
+
548
-
549
-
550
-
551
- ```
552
-
553
- <div>
554
-
555
- <div class = "col-md-4 offset-md-4">
556
-
557
- <h2 class = "text-center">new post</h2>
558
-
559
- <%= render partial: "form" %>
560
-
561
- </div>
562
-
563
- <div class = "col-md-4 offset-4">
564
-
565
- <%= link_to 'トップ', root_path %>
566
-
567
- </div>
568
-
569
- </div>
570
-
571
- ```
572
-
573
-
574
-
575
- index.html.erb
576
-
577
-
578
-
579
- ```
580
-
581
- <%= render partial: "devise/shared/header" %>
582
-
583
-
584
-
585
- <%# 会員登録、ログイン%>
586
-
587
- <main role="main">
588
-
589
- <section class="jumbotron text-center">
590
-
591
- <div class="container">
592
-
593
- <h3>ワンペタノート</h3>
594
-
595
- <p class="lead text-muted">画像も投稿できる掲示板です</p>
596
-
597
- <p>
598
-
599
- <% if user_signed_in? %>
600
-
601
- <%= link_to "新規投稿", new_post_path, class: 'btn btn-primary my-2' %>
602
-
603
- <%= link_to "ログアウト", destroy_user_session_path, method: :delete, class: 'btn btn-primary my-2' %>
604
-
605
- <% else %>
606
-
607
- <%= link_to "新規登録", new_user_registration_path, class: 'btn btn-primary my-2' %>
608
-
609
- <%= link_to "ログイン", new_user_session_path, class: 'btn btn-primary my-2' %>
610
-
611
- <% end %>
612
-
613
- </p>
614
-
615
- </div>
616
-
617
- </section>
618
-
619
-
620
-
621
- <%= render partial: 'post', collection: @posts %>
622
-
623
- <%= render :partial => "devise/shared/footer" %>
624
-
625
- ```
626
632
 
627
633
  #ER図は以下のように考えてます。
628
634