1
0
Fork 0

Update form/controller stuff

This commit is contained in:
Andrew Tomaka 2015-10-20 17:39:36 -04:00
parent c9af398b8f
commit 793e18a8f9
3 changed files with 67 additions and 12 deletions

View file

@ -14,6 +14,9 @@ class Admin::CardsController < Admin::BaseController
def new
@card = Card.new
@card.build_hp_stat
@card.build_atk_stat
@card.build_def_stat
authorize @card
end
@ -60,11 +63,16 @@ class Admin::CardsController < Admin::BaseController
private
def card_params
params.require(:card).permit(:title, :character_id, :rarity_id, :type_id,
:leader_skill_id, :passive_skill_id, :verified,
:super_attack_id, :dokkan_id, :gameid,
:awaken_type_id, :dokkan_id,
evidence_ids: [], link_ids: [])
params
.require(:card)
.permit(:title, :character_id, :rarity_id, :type_id, :leader_skill_id,
:passive_skill_id, :verified, :super_attack_id, :dokkan_id,
:gameid, :awaken_type_id, :dokkan_id, evidence_ids: [],
link_ids: [],
hp_stat_attributes: [:min, :max, :awaken_min, :awaken_max],
atk_stat_attributes: [:min, :max, :awaken_min, :awaken_max],
def_stat_attributes: [:min, :max, :awaken_min, :awaken_max]
)
end
def set_card

View file

@ -14,6 +14,14 @@ class Card < ActiveRecord::Base
has_many :evidences
belongs_to :hp_stat, class_name: 'Stat'
belongs_to :atk_stat, class_name: 'Stat'
belongs_to :def_stat, class_name: 'Stat'
accepts_nested_attributes_for :hp_stat
accepts_nested_attributes_for :atk_stat
accepts_nested_attributes_for :def_stat
delegate :name, to: :character, prefix: false
validates :title, presence: true

View file

@ -25,6 +25,45 @@
.row
.col-md-6
= f.association :dokkan_card, collection: Card.includes(:character).all, label_method: :full_name
.row
.col-md-12
= f.label 'Health Points'
.row
= f.simple_fields_for :hp_stat do |hp|
.col-md-3
= hp.input :min
.col-md-3
= hp.input :max
.col-md-3
= hp.input :awaken_min
.col-md-3
= hp.input :awaken_max
.row
.col-md-12
= f.label 'Attack'
.row
= f.simple_fields_for :atk_stat do |hp|
.col-md-3
= hp.input :min
.col-md-3
= hp.input :max
.col-md-3
= hp.input :awaken_min
.col-md-3
= hp.input :awaken_max
.row
.col-md-12
= f.label 'Defense'
.row
= f.simple_fields_for :def_stat do |hp|
.col-md-3
= hp.input :min
.col-md-3
= hp.input :max
.col-md-3
= hp.input :awaken_min
.col-md-3
= hp.input :awaken_max
.row
.col-md-12
= f.label :links