Update form/controller stuff
This commit is contained in:
parent
c9af398b8f
commit
793e18a8f9
3 changed files with 67 additions and 12 deletions
|
@ -14,6 +14,9 @@ class Admin::CardsController < Admin::BaseController
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@card = Card.new
|
@card = Card.new
|
||||||
|
@card.build_hp_stat
|
||||||
|
@card.build_atk_stat
|
||||||
|
@card.build_def_stat
|
||||||
|
|
||||||
authorize @card
|
authorize @card
|
||||||
end
|
end
|
||||||
|
@ -60,11 +63,16 @@ class Admin::CardsController < Admin::BaseController
|
||||||
private
|
private
|
||||||
|
|
||||||
def card_params
|
def card_params
|
||||||
params.require(:card).permit(:title, :character_id, :rarity_id, :type_id,
|
params
|
||||||
:leader_skill_id, :passive_skill_id, :verified,
|
.require(:card)
|
||||||
:super_attack_id, :dokkan_id, :gameid,
|
.permit(:title, :character_id, :rarity_id, :type_id, :leader_skill_id,
|
||||||
:awaken_type_id, :dokkan_id,
|
:passive_skill_id, :verified, :super_attack_id, :dokkan_id,
|
||||||
evidence_ids: [], link_ids: [])
|
: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
|
end
|
||||||
|
|
||||||
def set_card
|
def set_card
|
||||||
|
|
|
@ -14,6 +14,14 @@ class Card < ActiveRecord::Base
|
||||||
|
|
||||||
has_many :evidences
|
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
|
delegate :name, to: :character, prefix: false
|
||||||
|
|
||||||
validates :title, presence: true
|
validates :title, presence: true
|
||||||
|
|
|
@ -25,6 +25,45 @@
|
||||||
.row
|
.row
|
||||||
.col-md-6
|
.col-md-6
|
||||||
= f.association :dokkan_card, collection: Card.includes(:character).all, label_method: :full_name
|
= 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
|
.row
|
||||||
.col-md-12
|
.col-md-12
|
||||||
= f.label :links
|
= f.label :links
|
||||||
|
@ -32,14 +71,14 @@
|
||||||
= f.association :links, as: :check_boxes, item_wrapper_tag: nil, item_label_class: 'checkbox-inline', label: false
|
= f.association :links, as: :check_boxes, item_wrapper_tag: nil, item_label_class: 'checkbox-inline', label: false
|
||||||
.row
|
.row
|
||||||
.col-md-12
|
.col-md-12
|
||||||
= f.label :evidences
|
= f.label :evidences
|
||||||
- unless @card.new_record?
|
- 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
|
div
|
||||||
span Current
|
span Unused
|
||||||
= 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) }
|
= 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) }
|
||||||
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) }
|
|
||||||
.row
|
.row
|
||||||
.col-md-12
|
.col-md-12
|
||||||
= f.label 'Verification'
|
= f.label 'Verification'
|
||||||
|
|
Loading…
Reference in a new issue