From 793e18a8f9ad1da06c44b431516f3f9ac597247a Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Tue, 20 Oct 2015 17:39:36 -0400 Subject: [PATCH] Update form/controller stuff --- app/controllers/admin/cards_controller.rb | 18 +++++--- app/models/card.rb | 8 ++++ app/views/admin/cards/_form.html.slim | 53 ++++++++++++++++++++--- 3 files changed, 67 insertions(+), 12 deletions(-) diff --git a/app/controllers/admin/cards_controller.rb b/app/controllers/admin/cards_controller.rb index 5e72599..e51a317 100644 --- a/app/controllers/admin/cards_controller.rb +++ b/app/controllers/admin/cards_controller.rb @@ -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 diff --git a/app/models/card.rb b/app/models/card.rb index 18845ab..b88c758 100644 --- a/app/models/card.rb +++ b/app/models/card.rb @@ -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 diff --git a/app/views/admin/cards/_form.html.slim b/app/views/admin/cards/_form.html.slim index 0adb3c1..2d99998 100644 --- a/app/views/admin/cards/_form.html.slim +++ b/app/views/admin/cards/_form.html.slim @@ -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'