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

74 lines
1.4 KiB
Ruby

class Admin::CardsController < Admin::BaseController
before_action :set_card, only: [:show, :edit, :update, :destroy]
after_action :verify_authorized
def index
@cards = Card.includes(:character).all
authorize Card
end
def show
authorize @card
end
def new
@card = Card.new
authorize @card
end
def create
@card = Card.new(card_params)
authorize @card
if @card.save
redirect_to admin_cards_path,
notice: "Card was created. #{undo_link(@card)}"
else
render :new
end
end
def edit
authorize @card
@versions = @card.versions
end
def update
authorize @card
if @card.update(card_params)
redirect_to admin_cards_path,
notice: "Card was updated. #{undo_link(@card)}"
else
render :edit
end
end
def destroy
authorize @card
@card.destroy
redirect_to admin_cards_path,
notice: "Card was deleted. #{undo_link(@card)}"
end
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: [])
end
def set_card
@card = Card.find(params[:id])
end
end