質問編集履歴

8

回答を受けて訂正

2018/08/01 11:26

投稿

Manamin
Manamin

スコア14

test CHANGED
File without changes
test CHANGED
@@ -24,6 +24,22 @@
24
24
 
25
25
 
26
26
 
27
+ <%= form_for(@post, :html => {:multipart => true}) do |f| %>
28
+
29
+ を記述した後のパラメーターやコンソール
30
+
31
+
32
+
33
+ :multipart => trueの指定が反映されず
34
+
35
+ ![イメージ説明](fc660c91a437ecd6628b76b22ccc048f.png)
36
+
37
+
38
+
39
+ ![イメージ説明](c804f8472781f3bc6108753a68ea010c.png)
40
+
41
+
42
+
27
43
  **読んだ記事**
28
44
 
29
45
  https://qiita.com/ttaka66/items/264dcb85e41f9135685c
@@ -68,7 +84,7 @@
68
84
 
69
85
  <tbody>
70
86
 
71
- <%= form_for(@post, html: { multipart: true }) do |f| %>
87
+ <%= form_for(@post, html: { multipart: true }) do |f| %> // ここ
72
88
 
73
89
  <div class="field">
74
90
 

7

multipart: true

2018/08/01 11:26

投稿

Manamin
Manamin

スコア14

test CHANGED
File without changes
test CHANGED
@@ -68,7 +68,7 @@
68
68
 
69
69
  <tbody>
70
70
 
71
- <%= form_for @post do |f| %>
71
+ <%= form_for(@post, html: { multipart: true }) do |f| %>
72
72
 
73
73
  <div class="field">
74
74
 

6

補足

2018/08/01 07:21

投稿

Manamin
Manamin

スコア14

test CHANGED
File without changes
test CHANGED
@@ -10,6 +10,18 @@
10
10
 
11
11
 
12
12
 
13
+ Already linked: /usr/local/Cellar/imagemagick@6/6.9.9-42
14
+
15
+ と表示されるのでimagemagickは6系でrmagickは確認したところ2.16.0です。
16
+
17
+
18
+
19
+ なおパラメーターにはimageが渡ってきているものの、createアクション時のPost.newにはデータを渡せてないようです。
20
+
21
+
22
+
23
+ ![イメージ説明](3e67b5a6235a8ca62d9a228b2b58ad6f.png)
24
+
13
25
 
14
26
 
15
27
  **読んだ記事**

5

訂正

2018/07/12 04:43

投稿

Manamin
Manamin

スコア14

test CHANGED
File without changes
test CHANGED
@@ -436,8 +436,6 @@
436
436
 
437
437
  before_action :set_post, only: [:show, :edit, :update, :destroy]
438
438
 
439
- before_action :post_params, only: [:create, :update]
440
-
441
439
  before_action :current_user
442
440
 
443
441
 

4

before_action

2018/07/12 00:11

投稿

Manamin
Manamin

スコア14

test CHANGED
File without changes
test CHANGED
@@ -436,6 +436,8 @@
436
436
 
437
437
  before_action :set_post, only: [:show, :edit, :update, :destroy]
438
438
 
439
+ before_action :post_params, only: [:create, :update]
440
+
439
441
  before_action :current_user
440
442
 
441
443
 

3

訂正

2018/07/12 00:09

投稿

Manamin
Manamin

スコア14

test CHANGED
File without changes
test CHANGED
@@ -430,7 +430,7 @@
430
430
 
431
431
 
432
432
 
433
- ``
433
+ ```
434
434
 
435
435
  class PostsController < ApplicationController
436
436
 

2

訂正

2018/07/12 00:05

投稿

Manamin
Manamin

スコア14

test CHANGED
File without changes
test CHANGED
@@ -428,6 +428,8 @@
428
428
 
429
429
  ```
430
430
 
431
+
432
+
431
433
  ``
432
434
 
433
435
  class PostsController < ApplicationController
@@ -594,9 +596,9 @@
594
596
 
595
597
  end
596
598
 
597
-
598
-
599
- ```
599
+ ```
600
+
601
+
600
602
 
601
603
  ```
602
604
 

1

コントローラー追加

2018/07/12 00:04

投稿

Manamin
Manamin

スコア14

test CHANGED
File without changes
test CHANGED
@@ -428,7 +428,175 @@
428
428
 
429
429
  ```
430
430
 
431
-
431
+ ``
432
+
433
+ class PostsController < ApplicationController
434
+
435
+ before_action :set_post, only: [:show, :edit, :update, :destroy]
436
+
437
+ before_action :current_user
438
+
439
+
440
+
441
+ # GET /posts
442
+
443
+ # GET /posts.json
444
+
445
+ def index
446
+
447
+ @posts = Post.all
448
+
449
+ end
450
+
451
+
452
+
453
+ # GET /posts/1
454
+
455
+ # GET /posts/1.json
456
+
457
+ def show
458
+
459
+ end
460
+
461
+
462
+
463
+ # GET /posts/new
464
+
465
+ def new
466
+
467
+ @post = Post.new
468
+
469
+ end
470
+
471
+
472
+
473
+ # GET /posts/1/edit
474
+
475
+ def edit
476
+
477
+ end
478
+
479
+
480
+
481
+ # POST /posts
482
+
483
+ # POST /posts.json
484
+
485
+ def create
486
+
487
+ @post = Post.new(post_params)
488
+
489
+ @post.user_id = @current_user.id
490
+
491
+
492
+
493
+ binding.pry
494
+
495
+
496
+
497
+ respond_to do |format|
498
+
499
+ if @post.save
500
+
501
+ format.html { redirect_to @post, notice: 'Post was successfully created.' }
502
+
503
+ format.json { render :show, status: :created, location: @post }
504
+
505
+ else
506
+
507
+ format.html { render :new }
508
+
509
+ format.json { render json: @post.errors, status: :unprocessable_entity }
510
+
511
+ end
512
+
513
+ end
514
+
515
+ end
516
+
517
+
518
+
519
+ # PATCH/PUT /posts/1
520
+
521
+ # PATCH/PUT /posts/1.json
522
+
523
+ def update
524
+
525
+ respond_to do |format|
526
+
527
+ if @post.update(post_params)
528
+
529
+ format.html { redirect_to @post, notice: 'Post was successfully updated.' }
530
+
531
+ format.json { render :show, status: :ok, location: @post }
532
+
533
+ else
534
+
535
+ format.html { render :edit }
536
+
537
+ format.json { render json: @post.errors, status: :unprocessable_entity }
538
+
539
+ end
540
+
541
+ end
542
+
543
+ end
544
+
545
+
546
+
547
+ # DELETE /posts/1
548
+
549
+ # DELETE /posts/1.json
550
+
551
+ def destroy
552
+
553
+ @post.destroy
554
+
555
+ respond_to do |format|
556
+
557
+ format.html { redirect_to posts_url, notice: 'Post was successfully destroyed.' }
558
+
559
+ format.json { head :no_content }
560
+
561
+ end
562
+
563
+ end
564
+
565
+
566
+
567
+ private
568
+
569
+ # Use callbacks to share common setup or constraints between actions.
570
+
571
+ def set_post
572
+
573
+ @post = Post.find(params[:id])
574
+
575
+ end
576
+
577
+
578
+
579
+ # Never trust parameters from the scary internet, only allow the white list through.
580
+
581
+ def post_params
582
+
583
+ params.require(:post).permit(:name, :user_id, :image, :body, :tec, :point, :link)
584
+
585
+ end
586
+
587
+
588
+
589
+ def current_user
590
+
591
+ @current_user = User.find_by(id: session[:user_id])
592
+
593
+ end
594
+
595
+ end
596
+
597
+
598
+
599
+ ```
432
600
 
433
601
  ```
434
602