1
0
Fork 0
dokkan-data-rails/app/controllers/admin/cards_controller.rb

82 lines
1.6 KiB
Ruby
Raw Normal View History

2015-10-09 08:17:29 -04:00
class Admin::CardsController < Admin::BaseController
2015-10-06 13:55:12 -04:00
before_action :set_card, only: [:show, :edit, :update, :destroy]
2015-10-08 15:18:21 -04:00
after_action :verify_authorized
2015-10-06 13:55:12 -04:00
def index
2015-10-08 13:02:25 -04:00
@cards = Card.includes(:character).all
2015-10-08 15:18:21 -04:00
authorize Card
2015-10-06 13:55:12 -04:00
end
def show
2015-10-08 15:18:21 -04:00
authorize @card
2015-10-06 13:55:12 -04:00
end
def new
@card = Card.new
2015-10-20 17:39:36 -04:00
@card.build_hp_stat
@card.build_atk_stat
@card.build_def_stat
2015-10-08 15:18:21 -04:00
authorize @card
2015-10-06 13:55:12 -04:00
end
def create
@card = Card.new(card_params)
2015-10-08 15:18:21 -04:00
authorize @card
2015-10-06 13:55:12 -04:00
if @card.save
2015-10-14 09:21:16 -04:00
redirect_to admin_cards_path,
notice: "Card was created. #{undo_link(@card)}"
2015-10-06 13:55:12 -04:00
else
render :new
end
end
def edit
2015-10-08 15:18:21 -04:00
authorize @card
@versions = @card.versions
2015-10-06 13:55:12 -04:00
end
def update
2015-10-08 15:18:21 -04:00
authorize @card
2015-10-06 13:55:12 -04:00
if @card.update(card_params)
2015-10-14 09:21:16 -04:00
redirect_to admin_cards_path,
notice: "Card was updated. #{undo_link(@card)}"
2015-10-06 13:55:12 -04:00
else
render :edit
end
end
def destroy
2015-10-08 15:18:21 -04:00
authorize @card
2015-10-06 13:55:12 -04:00
@card.destroy
2015-10-14 09:21:16 -04:00
redirect_to admin_cards_path,
notice: "Card was deleted. #{undo_link(@card)}"
2015-10-06 13:55:12 -04:00
end
private
def card_params
2015-10-20 17:39:36 -04:00
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]
)
2015-10-06 13:55:12 -04:00
end
def set_card
@card = Card.find(params[:id])
end
end