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

65 lines
1.1 KiB
Ruby
Raw Normal View History

2015-10-09 08:17:29 -04:00
class Admin::CharactersController < Admin::BaseController
2015-10-06 13:55:12 -04:00
before_action :set_character, 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
@characters = Character.all
2015-10-08 15:18:21 -04:00
authorize Character
2015-10-06 13:55:12 -04:00
end
def show
2015-10-08 15:18:21 -04:00
authorize @character
2015-10-06 13:55:12 -04:00
end
def new
@character = Character.new
2015-10-08 15:18:21 -04:00
authorize @character
2015-10-06 13:55:12 -04:00
end
def create
@character = Character.new(character_params)
2015-10-08 15:18:21 -04:00
authorize @character
2015-10-06 13:55:12 -04:00
if @character.save
2015-10-09 08:17:29 -04:00
redirect_to admin_characters_path, notice: 'Character 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 @character
2015-10-06 13:55:12 -04:00
end
def update
2015-10-08 15:18:21 -04:00
authorize @character
2015-10-06 13:55:12 -04:00
if @character.update(character_params)
2015-10-09 08:17:29 -04:00
redirect_to admin_characters_path, notice: 'Character 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 @character
2015-10-06 13:55:12 -04:00
@character.destroy
2015-10-09 08:17:29 -04:00
redirect_to admin_characters_path, notice: 'Character was deleted'
2015-10-06 13:55:12 -04:00
end
private
def character_params
params.require(:character).permit(:name)
end
def set_character
@character = Character.find(params[:id])
end
end