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
@ -32,14 +71,14 @@
= f.association :links, as: :check_boxes, item_wrapper_tag: nil, item_label_class: 'checkbox-inline', label: false
.row
.col-md-12
= f.label :evidences
- unless @card.new_record?
= f.label :evidences
- unless @card.new_record?
div
span Current
= f.association :evidences, as: :check_boxes, collection: Evidence.for(@card), item_wrapper_tag: nil, item_label_class: 'checkbox-inline', label: false, label_method: lambda { |evidence| evidence_checkbox_label(evidence) }
div
span Current
= f.association :evidences, as: :check_boxes, collection: Evidence.for(@card), item_wrapper_tag: nil, item_label_class: 'checkbox-inline', label: false, label_method: lambda { |evidence| evidence_checkbox_label(evidence) }
div
span Unused
= f.association :evidences, as: :check_boxes, collection: Evidence.unused, item_wrapper_tag: nil, item_label_class: 'checkbox-inline', label: false, label_method: lambda { |evidence| evidence_checkbox_label(evidence) }
span Unused
= f.association :evidences, as: :check_boxes, collection: Evidence.unused, item_wrapper_tag: nil, item_label_class: 'checkbox-inline', label: false, label_method: lambda { |evidence| evidence_checkbox_label(evidence) }
.row
.col-md-12
= f.label 'Verification'