質問編集履歴

1

parties_controllerを追記しました。

2020/09/12 12:46

投稿

Rvato
Rvato

スコア6

test CHANGED
File without changes
test CHANGED
@@ -293,3 +293,133 @@
293
293
  仮説として問題が、hamlの記述かもしくはモデルにあると思っていますが見当つきません。
294
294
 
295
295
  何か気づきがありましたらご意見頂戴したいです。
296
+
297
+
298
+
299
+ ### 追記 [2020.9.12]
300
+
301
+ ▼ parties_controller
302
+
303
+ ```
304
+
305
+ class PartiesController < ApplicationController
306
+
307
+
308
+
309
+ def index
310
+
311
+ end
312
+
313
+
314
+
315
+ def new
316
+
317
+ @pokemon = Pokemon.new
318
+
319
+ @party = Party.new
320
+
321
+ @party.build_pokemon
322
+
323
+ end
324
+
325
+
326
+
327
+ def create
328
+
329
+ @pokemon = Pokemon.new(pokemon_params)
330
+
331
+ @pokemon.save
332
+
333
+ @party = Party.new(party_params)
334
+
335
+ @party.save
336
+
337
+ redirect_to root_path, notice: 'パーティを作成しました'
338
+
339
+ end
340
+
341
+
342
+
343
+ def show
344
+
345
+ @party = Party.find(params[:id])
346
+
347
+ end
348
+
349
+
350
+
351
+ def edit
352
+
353
+ @party = Party.find(params[:id])
354
+
355
+ end
356
+
357
+
358
+
359
+ def update
360
+
361
+ @party = Party.find(params[:id])
362
+
363
+ end
364
+
365
+
366
+
367
+ def destroy
368
+
369
+ @party = Party.find(params[:id])
370
+
371
+ end
372
+
373
+
374
+
375
+ private
376
+
377
+
378
+
379
+ def pokemon_params
380
+
381
+ params.permit(
382
+
383
+ :name, :nickname, :gender, :ability, :nature, :item, :move1, :move2, :move3, :move4,
384
+
385
+ :cs_hp, :cs_attack, :cs_defense, :cs_special_attack, :cs_special_defense, :cs_speed,
386
+
387
+ :bs_hp, :bs_attack, :bs_defense, :bs_special_attack, :bs_special_defense, :bs_speed,
388
+
389
+ :ev_hp, :ev_attack, :ev_defense, :ev_special_attack, :ev_special_defense, :ev_speed
390
+
391
+ )
392
+
393
+ end
394
+
395
+
396
+
397
+ def party_params
398
+
399
+ params.permit(
400
+
401
+ :party_name,
402
+
403
+ pokemons_attributes:[
404
+
405
+ :name, :nickname, :gender, :ability, :nature, :item, :move1, :move2, :move3, :move4,
406
+
407
+ :cs_hp, :cs_attack, :cs_defense, :cs_special_attack, :cs_special_defense, :cs_speed,
408
+
409
+ :bs_hp, :bs_attack, :bs_defense, :bs_special_attack, :bs_special_defense, :bs_speed,
410
+
411
+ :ev_hp, :ev_attack, :ev_defense, :ev_special_attack, :ev_special_defense, :ev_speed
412
+
413
+ ]
414
+
415
+ )
416
+
417
+ end
418
+
419
+
420
+
421
+ end
422
+
423
+
424
+
425
+ ```