質問編集履歴

2

エラーの追加、および修正したファイルの追加

2019/01/12 05:26

投稿

-maeji-
-maeji-

スコア39

test CHANGED
File without changes
test CHANGED
@@ -215,3 +215,163 @@
215
215
  :追記
216
216
 
217
217
  ![イメージ説明](e876392e48f44f10f7a254d488aa12b0.png)
218
+
219
+
220
+
221
+ ![イメージ説明](3afa4cf1b94759178ee53f09de3ba44e.png)
222
+
223
+
224
+
225
+
226
+
227
+
228
+
229
+ tasks_controller.rb
230
+
231
+
232
+
233
+ ```rb
234
+
235
+ class TasksController < ApplicationController
236
+
237
+ def index
238
+
239
+ @tasks = Task.all
240
+
241
+ end
242
+
243
+
244
+
245
+ def new
246
+
247
+ @task = Task.new
248
+
249
+ end
250
+
251
+
252
+
253
+ def edit
254
+
255
+ @task = Task.find(params[:id])
256
+
257
+ end
258
+
259
+
260
+
261
+
262
+
263
+ def create
264
+
265
+ @task = Task.new(tasks_param)
266
+
267
+ #@task = Task.new(title: params[:task][:title], content: params[:task][:content])
268
+
269
+
270
+
271
+ if @task.save
272
+
273
+ redirect_to tasks_url
274
+
275
+ else
276
+
277
+ render :new
278
+
279
+ end
280
+
281
+ end
282
+
283
+
284
+
285
+
286
+
287
+ def update
288
+
289
+ @task = Task.find(params[:id])
290
+
291
+ if @task.update(tasks_param)
292
+
293
+ redirect_to tasks_path
294
+
295
+ else
296
+
297
+ render :edit
298
+
299
+ end
300
+
301
+ end
302
+
303
+
304
+
305
+
306
+
307
+ def destroy
308
+
309
+  @task = Task.find(params[:id])
310
+
311
+  @task.destroy!
312
+
313
+ redirect_to tasks_path
314
+
315
+ end
316
+
317
+
318
+
319
+ private
320
+
321
+ def tasks_param
322
+
323
+ params.require(:task).permit(:title, :content)
324
+
325
+ end
326
+
327
+ end
328
+
329
+ ```
330
+
331
+
332
+
333
+ index.html.erb
334
+
335
+
336
+
337
+ ```rb
338
+
339
+ <h1>タスク一覧</h1>
340
+
341
+ <ul>
342
+
343
+
344
+
345
+ <% @tasks.each do |task| %>
346
+
347
+ <li>
348
+
349
+ title: <%= task.title %>
350
+
351
+ </li>
352
+
353
+
354
+
355
+ <li>
356
+
357
+ content: <%= task.content %>
358
+
359
+ </li>
360
+
361
+
362
+
363
+
364
+
365
+ <%= link_to '削除', task_path(task.id),
366
+
367
+ method: :delete, data: { confirm: "削除してよろしいですか?", commit: "削除する", cancel: "やめる", title: "ご確認ください" } %>
368
+
369
+ <% end %>
370
+
371
+
372
+
373
+
374
+
375
+ </ul>
376
+
377
+ ```

1

エラーメッセージ追記

2019/01/12 05:26

投稿

-maeji-
-maeji-

スコア39

test CHANGED
File without changes
test CHANGED
@@ -209,3 +209,9 @@
209
209
  </ul>
210
210
 
211
211
  ```
212
+
213
+
214
+
215
+ :追記
216
+
217
+ ![イメージ説明](e876392e48f44f10f7a254d488aa12b0.png)