質問編集履歴

1

コントローラー追記しました

2020/12/06 09:48

投稿

koyashika
koyashika

スコア1

title CHANGED
File without changes
body CHANGED
@@ -12,6 +12,9 @@
12
12
  何か良い方法がございましたら、ご教授頂ければと思います。
13
13
  よろしくお願い致します。
14
14
 
15
+ コントローラーのコード追記しました。
16
+ 情報不足ですみません、、
17
+ よろしくお願い致します。
15
18
 
16
19
 
17
20
  ### 該当のソースコード
@@ -36,4 +39,33 @@
36
39
  end
37
40
  end
38
41
 
42
+ ```
43
+ ```ruby
44
+ class WeightsController < ApplicationController
45
+ def index
46
+ @weights = Weight.all
47
+ end
48
+
49
+ def new
50
+ @weight = Weight.new
51
+ end
52
+
53
+ def create
54
+ @weight = Weight.create(weight_params)
55
+ if @weight.save
56
+ redirect_to weights_path, notice: '体重が送信されました'
57
+ else
58
+ redirect_to weights_path, notice: '体重を送信してください'
59
+
60
+ end
61
+ end
62
+
63
+ private
64
+
65
+ def weight_params
66
+ params.permit(:kg).merge(user_id: current_user.id)
67
+ end
68
+ end
69
+
70
+
39
71
  ```