質問編集履歴

1

message_controller.rbを追記いたしました。

2021/10/03 08:04

投稿

linkwood
linkwood

スコア0

test CHANGED
File without changes
test CHANGED
@@ -162,6 +162,114 @@
162
162
 
163
163
  ```
164
164
 
165
+ app/controllers/messages_controller.rb
166
+
167
+ ```
168
+
169
+ class MessagesController < ApplicationController
170
+
171
+ layout "messages"
172
+
173
+
174
+
175
+ def index
176
+
177
+ @msg = "Massage data."
178
+
179
+ @data = Message.all
180
+
181
+ end
182
+
183
+
184
+
185
+ def show
186
+
187
+ @msg = "Indexed data."
188
+
189
+ @message = Message.find(params[:id])
190
+
191
+ end
192
+
193
+
194
+
195
+ def add
196
+
197
+ @msg = "Massege data."
198
+
199
+ @message = Message.new
200
+
201
+ end
202
+
203
+
204
+
205
+ def create
206
+
207
+ @message = Message.new message_params
208
+
209
+ if @message.save then
210
+
211
+ redirect_to "/messages"
212
+
213
+ else
214
+
215
+ render "add"
216
+
217
+ end
218
+
219
+ end
220
+
221
+
222
+
223
+ def edit
224
+
225
+ @msg = "edit data.[id = " + params[:id] + "]"
226
+
227
+ @message = Message.find(params[:id])
228
+
229
+ end
230
+
231
+
232
+
233
+ def update
234
+
235
+ obj = Message.find(params[:id])
236
+
237
+ obj.update(message_params)
238
+
239
+ redirect_to "/messages"
240
+
241
+ end
242
+
243
+
244
+
245
+ def delete
246
+
247
+ obj = Message.find(params[:id])
248
+
249
+ obj.destroy
250
+
251
+ redirect_to "/messages"
252
+
253
+ end
254
+
255
+
256
+
257
+ private
258
+
259
+ def message_params
260
+
261
+ params.require(:message).permit(:person_id, :title, :message)
262
+
263
+ end
264
+
265
+
266
+
267
+ end
268
+
269
+
270
+
271
+ ```
272
+
165
273
 
166
274
 
167
275
  ### 試したこと