質問編集履歴
1
掲載したコードを増やしました
test
CHANGED
File without changes
|
test
CHANGED
@@ -46,9 +46,27 @@
|
|
46
46
|
|
47
47
|
categoriesコントローラー
|
48
48
|
|
49
|
+
|
50
|
+
|
51
|
+
class CategoriesController < ApplicationController
|
52
|
+
|
53
|
+
before_action :set_category,only:[:show,:destroy,:edit,:update]
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
def index
|
58
|
+
|
59
|
+
@categories = Category.all
|
60
|
+
|
61
|
+
@category = Category.new
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
|
49
67
|
def show
|
50
68
|
|
51
|
-
|
69
|
+
|
52
70
|
|
53
71
|
@todos = @category.todos
|
54
72
|
|
@@ -58,6 +76,80 @@
|
|
58
76
|
|
59
77
|
|
60
78
|
|
79
|
+
def create
|
80
|
+
|
81
|
+
@category = Category.create(category_params)
|
82
|
+
|
83
|
+
if @category.save
|
84
|
+
|
85
|
+
redirect_to root_path
|
86
|
+
|
87
|
+
else
|
88
|
+
|
89
|
+
render :index
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
def edit
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
def update
|
104
|
+
|
105
|
+
@category.update(category_params)
|
106
|
+
|
107
|
+
if @category.save
|
108
|
+
|
109
|
+
redirect_to root_path
|
110
|
+
|
111
|
+
else
|
112
|
+
|
113
|
+
render :index
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
def destroy
|
122
|
+
|
123
|
+
@category.destroy
|
124
|
+
|
125
|
+
redirect_to root_path
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
private
|
132
|
+
|
133
|
+
def category_params
|
134
|
+
|
135
|
+
params.require(:category).permit( :name)
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
def set_category
|
142
|
+
|
143
|
+
@category = Category.find(params[:id])
|
144
|
+
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
|
152
|
+
|
61
153
|
|
62
154
|
|
63
155
|
```
|
@@ -138,7 +230,19 @@
|
|
138
230
|
|
139
231
|
ビュー
|
140
232
|
|
141
|
-
|
233
|
+
cetagories/show.html.haml
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
= form_for [@category,@todo] , html: { class: "category" } do |f|
|
238
|
+
|
239
|
+
%p Todo
|
240
|
+
|
241
|
+
= f.text_area :description, placeholder: "Todoタスクを入力してください(150字以内)", type: "text", class: 'category__name'
|
242
|
+
|
243
|
+
= f.date_field :date, type:"date"
|
244
|
+
|
245
|
+
= f.submit '作成する', class: 'category__submit'
|
142
246
|
|
143
247
|
- if @todos.present?
|
144
248
|
|
@@ -154,8 +258,10 @@
|
|
154
258
|
|
155
259
|
.category-box__edit
|
156
260
|
|
261
|
+
|
262
|
+
|
157
|
-
= link_to '削除', category_todo_path(todo.id), method: :delete
|
263
|
+
= link_to '削除', category_todo_path(@category.id,todo.id), method: :delete
|
158
|
-
|
159
|
-
|
160
|
-
|
264
|
+
|
265
|
+
|
266
|
+
|
161
|
-
```
|
267
|
+
```
|