質問編集履歴
2
訂正
test
CHANGED
File without changes
|
test
CHANGED
@@ -82,7 +82,69 @@
|
|
82
82
|
|
83
83
|
```app/controller/tasks_controller
|
84
84
|
|
85
|
+
```
|
86
|
+
|
87
|
+
class TasksController < ApplicationController
|
88
|
+
|
89
|
+
before_action :require_user_logged_in, only: [:index, :show]
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
def index
|
96
|
+
|
97
|
+
@tasks = Task.all
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
def show
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
def new
|
110
|
+
|
111
|
+
@task = Task.new
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
def create
|
118
|
+
|
119
|
+
@task = Task.new(task_params)
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
if @task.save
|
124
|
+
|
125
|
+
flash[:success] = 'Task が正常に投稿されました'
|
126
|
+
|
127
|
+
redirect_to @task
|
128
|
+
|
129
|
+
else
|
130
|
+
|
131
|
+
flash.now[:danger] = 'Task が投稿されませんでした'
|
132
|
+
|
133
|
+
render :new
|
134
|
+
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
def edit
|
142
|
+
|
143
|
+
end
|
144
|
+
|
145
|
+
|
146
|
+
|
85
|
-
|
147
|
+
def update
|
86
148
|
|
87
149
|
if @task.update(task_params)
|
88
150
|
|
@@ -144,6 +206,8 @@
|
|
144
206
|
|
145
207
|
|
146
208
|
|
209
|
+
|
210
|
+
|
147
211
|
```
|
148
212
|
|
149
213
|
###自分で調べたことや試したこと
|
1
tasks_controller追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -80,6 +80,70 @@
|
|
80
80
|
|
81
81
|
<%= link_to '新規タスクの投稿', new_task_path %>
|
82
82
|
|
83
|
+
```app/controller/tasks_controller
|
84
|
+
|
85
|
+
```def update
|
86
|
+
|
87
|
+
if @task.update(task_params)
|
88
|
+
|
89
|
+
flash[:success] = 'Task は正常に更新されました'
|
90
|
+
|
91
|
+
redirect_to @task
|
92
|
+
|
93
|
+
else
|
94
|
+
|
95
|
+
flash.now[:danger] = 'Task は更新されませんでした'
|
96
|
+
|
97
|
+
render :edit
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
def destroy
|
106
|
+
|
107
|
+
@task.destroy
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
flash[:success] = 'Task は正常に削除されました'
|
112
|
+
|
113
|
+
redirect_to tasks_url
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
private
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
# Strong Parameter
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
def set_task
|
128
|
+
|
129
|
+
@task = Task.find(params[:id])
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
def task_params
|
136
|
+
|
137
|
+
params.require(:task).permit(:content, :status)
|
138
|
+
|
139
|
+
end
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
end
|
144
|
+
|
145
|
+
|
146
|
+
|
83
147
|
```
|
84
148
|
|
85
149
|
###自分で調べたことや試したこと
|