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

73 lines
1.3 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-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-08 13:02:25 -04:00
params.require(:card).permit(:title, :character_id, :rarity_id, :type_id,
2015-10-14 11:20:02 -04:00
:leader_skill_id, :passive_skill_id, :verified,
2015-10-06 13:55:12 -04:00
: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