質問編集履歴
2
文法の修正
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
Routing Error
|
test
CHANGED
File without changes
|
1
書式の改善
test
CHANGED
File without changes
|
test
CHANGED
@@ -6,7 +6,13 @@
|
|
6
6
|
|
7
7
|
今回実装できずにいるのは"RESET"のボタンです。
|
8
8
|
|
9
|
+
|
10
|
+
|
11
|
+
**Routing Error**
|
12
|
+
|
9
|
-
|
13
|
+
No route matches [POST] "/orders/destroy_all"
|
14
|
+
|
15
|
+
|
10
16
|
|
11
17
|
|
12
18
|
|
@@ -18,7 +24,67 @@
|
|
18
24
|
|
19
25
|
```
|
20
26
|
|
27
|
+
class OrdersController < ApplicationController
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
def index
|
32
|
+
|
33
|
+
@user_food = UserFood.new
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
@user_foods = UserFood.all
|
38
|
+
|
39
|
+
price = UserFood.sum(:price)
|
40
|
+
|
41
|
+
quantity = UserFood.sum(:quantity)
|
42
|
+
|
43
|
+
@total = price
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
def new
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
def create
|
56
|
+
|
57
|
+
user_food = UserFood.find_by(food: params[:food])
|
58
|
+
|
59
|
+
if user_food.nil?
|
60
|
+
|
61
|
+
user_food = UserFood.new(user_food_params)
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
if user_food.save
|
66
|
+
|
67
|
+
redirect_to root_path
|
68
|
+
|
69
|
+
else
|
70
|
+
|
71
|
+
render order: :index
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
else
|
78
|
+
|
79
|
+
user_food.increment(quantity:1);
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
|
21
|
-
def destroy
|
87
|
+
def destroy
|
22
88
|
|
23
89
|
order = UserFood.find(params[:id])
|
24
90
|
|
@@ -28,6 +94,32 @@
|
|
28
94
|
|
29
95
|
end
|
30
96
|
|
97
|
+
|
98
|
+
|
99
|
+
def destroy_all
|
100
|
+
|
101
|
+
UserFood.destroy_all
|
102
|
+
|
103
|
+
redirect_to root_path
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
private
|
110
|
+
|
111
|
+
def user_food_params
|
112
|
+
|
113
|
+
params.require(:user_food).permit(:food, :price, :quantity)
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
end
|
120
|
+
|
121
|
+
|
122
|
+
|
31
123
|
```
|
32
124
|
|
33
125
|
|
@@ -36,7 +128,17 @@
|
|
36
128
|
|
37
129
|
```
|
38
130
|
|
131
|
+
.right-bar
|
132
|
+
|
133
|
+
.order-list
|
134
|
+
|
135
|
+
- @user_foods.each do |user_food|
|
136
|
+
|
137
|
+
.order-box
|
138
|
+
|
139
|
+
.order-box__deta
|
140
|
+
|
39
|
-
.order-box__deta--name
|
141
|
+
.order-box__deta--name
|
40
142
|
|
41
143
|
= user_food.food
|
42
144
|
|
@@ -50,6 +152,62 @@
|
|
50
152
|
|
51
153
|
.reset-box
|
52
154
|
|
53
|
-
= link_to "RESET",:
|
155
|
+
= link_to "RESET", destroy_all_orders_path, method: :derete
|
156
|
+
|
54
|
-
|
157
|
+
.price-box
|
158
|
+
|
159
|
+
.price-box__deta
|
160
|
+
|
161
|
+
.price-box__deta--yen
|
162
|
+
|
163
|
+
¥
|
164
|
+
|
165
|
+
.price-box__deta--price
|
166
|
+
|
167
|
+
= @total
|
168
|
+
|
55
|
-
```
|
169
|
+
```
|
170
|
+
|
171
|
+
##Routes.rb
|
172
|
+
|
173
|
+
```
|
174
|
+
|
175
|
+
Rails.application.routes.draw do
|
176
|
+
|
177
|
+
root "orders#index"
|
178
|
+
|
179
|
+
resources :orders, only: [:index, :new, :create, :destroy,]do
|
180
|
+
|
181
|
+
collection do
|
182
|
+
|
183
|
+
delete 'destroy_all'
|
184
|
+
|
185
|
+
end
|
186
|
+
|
187
|
+
end
|
188
|
+
|
189
|
+
end
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
```
|
194
|
+
|
195
|
+
##rails routes
|
196
|
+
|
197
|
+
```
|
198
|
+
|
199
|
+
Prefix Verb URI Pattern Controller#Action
|
200
|
+
|
201
|
+
root GET / orders#index
|
202
|
+
|
203
|
+
destroy_all_orders DELETE /orders/destroy_all(.:format) orders#destroy_all
|
204
|
+
|
205
|
+
orders GET /orders(.:format) orders#index
|
206
|
+
|
207
|
+
POST /orders(.:format) orders#create
|
208
|
+
|
209
|
+
new_order GET /orders/new(.:format) orders#new
|
210
|
+
|
211
|
+
order DELETE /orders/:id(.:format) orders#destroy
|
212
|
+
|
213
|
+
```
|