質問編集履歴
1
追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -12,7 +12,7 @@
|
|
12
12
|
|
13
13
|
|
14
14
|
|
15
|
-
|
15
|
+
検証ツールにてエラーはなし
|
16
16
|
|
17
17
|
|
18
18
|
|
@@ -131,3 +131,65 @@
|
|
131
131
|
|
132
132
|
|
133
133
|
```
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
```
|
138
|
+
|
139
|
+
book.controller
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
def show
|
144
|
+
|
145
|
+
@book = Book.find(params[:id])
|
146
|
+
|
147
|
+
@message = Message.new
|
148
|
+
|
149
|
+
@favorite = Favorite.new
|
150
|
+
|
151
|
+
end
|
152
|
+
|
153
|
+
```
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
```
|
158
|
+
|
159
|
+
favorite.controller
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
class FavoritesController < ApplicationController
|
164
|
+
|
165
|
+
def create
|
166
|
+
|
167
|
+
@book = Book.find(params[:book_id])
|
168
|
+
|
169
|
+
@favorite = current_user.favorites.build(book_id: params[:book_id])
|
170
|
+
|
171
|
+
@favorite = favorites.find_by(book_id: book.id)
|
172
|
+
|
173
|
+
@favorite.save
|
174
|
+
|
175
|
+
redirect_to books_path
|
176
|
+
|
177
|
+
end
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
def destroy
|
182
|
+
|
183
|
+
@book = Book.find(params[:book_id])
|
184
|
+
|
185
|
+
@favorite = Favorite.find_by(book_id: params[:book_id], user_id: current_user.id)
|
186
|
+
|
187
|
+
@favorite.destroy
|
188
|
+
|
189
|
+
redirect_to books_path
|
190
|
+
|
191
|
+
end
|
192
|
+
|
193
|
+
end
|
194
|
+
|
195
|
+
```
|