質問編集履歴
1
tasks_controller.rbを追加しました
title
CHANGED
File without changes
|
body
CHANGED
@@ -43,7 +43,60 @@
|
|
43
43
|
|
44
44
|
|
45
45
|
```
|
46
|
+
#####tasks_controller.rb
|
47
|
+
```
|
48
|
+
class TasksController < ApplicationController
|
49
|
+
before_action :set_task, only: [:show, :edit, :update, :destroy]
|
50
|
+
def index
|
51
|
+
@tasks = current_user.tasks.order(created_at: :desc)
|
52
|
+
end
|
46
53
|
|
54
|
+
def show
|
55
|
+
end
|
56
|
+
|
57
|
+
def new
|
58
|
+
@task = Task.new
|
59
|
+
end
|
60
|
+
|
61
|
+
def edit
|
62
|
+
end
|
63
|
+
|
64
|
+
def update
|
65
|
+
task.update!(task_params)
|
66
|
+
redirect_to tasks_url, notice:"タスク『#{task.name}』を更新しました。"
|
67
|
+
end
|
68
|
+
|
69
|
+
def destroy
|
70
|
+
task.destroy
|
71
|
+
redirect_to tasks_url, notice:"タスク『#{task.name}」を削除しました。"
|
72
|
+
end
|
73
|
+
|
74
|
+
def create
|
75
|
+
@task = current_user.tasks.new(task_params)
|
76
|
+
|
77
|
+
if @task.save
|
78
|
+
redirect_to @task, notice: "タスク『#{@task.name}』を登録しました。"
|
79
|
+
else
|
80
|
+
render :new
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
private
|
89
|
+
|
90
|
+
def task_params
|
91
|
+
params.require(:task).permit(:name, :description)
|
92
|
+
end
|
93
|
+
|
94
|
+
def set_task
|
95
|
+
@task = current_user.tasks.find(params[:id])
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
```
|
47
100
|
### 試したこと
|
48
101
|
|
49
102
|
9行目と言われているため、idの新規登録?が出来ていないのかなと思うのですが
|