質問編集履歴
1
モデルを保存した時のコントローラのメソッドを追記しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -100,6 +100,32 @@
|
|
100
100
|
|
101
101
|
```
|
102
102
|
|
103
|
+
def new
|
104
|
+
|
105
|
+
@product = Product.new
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
def create
|
112
|
+
|
113
|
+
@product = Product.new(product_params)
|
114
|
+
|
115
|
+
if @product.save
|
116
|
+
|
117
|
+
redirect_to setting_detail_product_path(@product), notice:"新しい商品を作成・保存しました。"
|
118
|
+
|
119
|
+
else
|
120
|
+
|
121
|
+
render 'new', notice:"保存に失敗しました。"
|
122
|
+
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
|
128
|
+
|
103
129
|
def detail
|
104
130
|
|
105
131
|
@product = Product.find(params[:id])
|
@@ -108,6 +134,20 @@
|
|
108
134
|
|
109
135
|
|
110
136
|
|
137
|
+
def update
|
138
|
+
|
139
|
+
@product = Product.find(params[:id])
|
140
|
+
|
141
|
+
if @product.update(product_params)
|
142
|
+
|
143
|
+
redirect_back(fallback_location: setting_detail_product_path(@product), notice: "更新できました")
|
144
|
+
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
148
|
+
|
149
|
+
|
150
|
+
|
111
151
|
private
|
112
152
|
|
113
153
|
|