質問編集履歴
3
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -191,3 +191,145 @@
|
|
191
191
|
|
192
192
|
|
193
193
|
何とぞよろしくお願い致します・・・!
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
###質問に関する追記
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
camelubyさんの質問への追記情報
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
①この他にbefore_action等ありますか?
|
206
|
+
|
207
|
+
→特にありません!
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
②Gameにrankをセットしていろところは無いようなので。
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
→rankは中間テーブルにつけていて、Gameテーブルにはありません。
|
216
|
+
|
217
|
+
また、postで投げたrank情報は受け取ってはいるものの、前述のcreateのコードでどう使えばいいのか分からず・・・使えていません。。。
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
以下、Gameのテーブル情報です。
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
```ruby
|
226
|
+
|
227
|
+
class CreateGames < ActiveRecord::Migration[5.0]
|
228
|
+
|
229
|
+
def change
|
230
|
+
|
231
|
+
create_table :games do |t|
|
232
|
+
|
233
|
+
t.boolean :active, null: false, default: true
|
234
|
+
|
235
|
+
t.string :title, null: false, default: ''
|
236
|
+
|
237
|
+
t.string :icon, null: false, default: ''
|
238
|
+
|
239
|
+
t.string :level_name, null: false, default: ''
|
240
|
+
|
241
|
+
t.string :search_tag, null: false, default: ''
|
242
|
+
|
243
|
+
t.integer :feed_range, null: false, default: 0
|
244
|
+
|
245
|
+
t.integer :follower_num, null: false, default: 0
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
t.timestamps
|
250
|
+
|
251
|
+
end
|
252
|
+
|
253
|
+
end
|
254
|
+
|
255
|
+
end
|
256
|
+
|
257
|
+
```
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
最後に、自分なりに見直して以下のようなコードなら動くようにはなりました。
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
```ruby
|
266
|
+
|
267
|
+
class FollowGamesController < ApplicationController
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
before_action :set_game
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
def create
|
276
|
+
|
277
|
+
current_user.follow_games.create(game_id: @game, rank: @game_rank)
|
278
|
+
|
279
|
+
end
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
private
|
284
|
+
|
285
|
+
def set_game
|
286
|
+
|
287
|
+
@user = params[:follow_game][:user_id]
|
288
|
+
|
289
|
+
@game = params[:follow_game][:game_id]
|
290
|
+
|
291
|
+
@game_rank = params[:follow_game][:rank]
|
292
|
+
|
293
|
+
end
|
294
|
+
|
295
|
+
end
|
296
|
+
|
297
|
+
```
|
298
|
+
|
299
|
+
|
300
|
+
|
301
|
+
もともと載せていた以下のcreateのコードを利用する形でも前述の《ここが出来ない》の部分のことが実現出来るのでしょうか??
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
```ruby
|
306
|
+
|
307
|
+
class FollowGamesController < ApplicationController
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
before_action :set_game
|
312
|
+
|
313
|
+
|
314
|
+
|
315
|
+
def create
|
316
|
+
|
317
|
+
current_user.following_games << @game unless current_user.following_games.exists?(@game.id)
|
318
|
+
|
319
|
+
end
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
private
|
324
|
+
|
325
|
+
def set_game
|
326
|
+
|
327
|
+
@game = Game.find(params[:follow_game][:game_id])
|
328
|
+
|
329
|
+
@game_rank = params[:follow_game][:rank]
|
330
|
+
|
331
|
+
end
|
332
|
+
|
333
|
+
end
|
334
|
+
|
335
|
+
```
|
2
内容追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -186,4 +186,8 @@
|
|
186
186
|
|
187
187
|
|
188
188
|
|
189
|
+
もしかして、rankテーブルを別途用意するようなアプローチじゃないと難しいでしょうか??
|
190
|
+
|
191
|
+
|
192
|
+
|
189
193
|
何とぞよろしくお願い致します・・・!
|
1
誤表記修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -144,17 +144,7 @@
|
|
144
144
|
|
145
145
|
def create
|
146
146
|
|
147
|
-
current_user.follow_games << @game unless current_user.follow_games.exists?(@game.id)
|
147
|
+
current_user.following_games << @game unless current_user.following_games.exists?(@game.id)
|
148
|
-
|
149
|
-
end
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
def delete
|
154
|
-
|
155
|
-
current_user.follow_games.destroy(@game)
|
156
|
-
|
157
|
-
@game.reload
|
158
148
|
|
159
149
|
end
|
160
150
|
|