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-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-09 08:17:29 -04:00
|
|
|
redirect_to admin_cards_path, notice: 'Card was created'
|
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
|
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-09 08:17:29 -04:00
|
|
|
redirect_to admin_cards_path, notice: 'Card was updated'
|
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-09 08:17:29 -04:00
|
|
|
redirect_to admin_cards_path, notice: 'Card was deleted'
|
2015-10-06 13:55:12 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def card_params
|
2015-10-08 13:02:25 -04:00
|
|
|
params.require(:card).permit(:title, :character_id, :rarity_id, :type_id,
|
2015-10-06 13:55:12 -04:00
|
|
|
:leader_skill_id, :passive_skill_id,
|
|
|
|
:super_attack_id, :dokkan_id, :gameid,
|
2015-10-08 11:45:05 -04:00
|
|
|
:awaken_type_id, :dokkan_id, link_ids: [])
|
2015-10-06 13:55:12 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def set_card
|
|
|
|
@card = Card.find(params[:id])
|
|
|
|
end
|
|
|
|
end
|