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

65 lines
1.1 KiB
Ruby
Raw Normal View History

2015-10-06 13:55:12 -04:00
class CharactersController < ApplicationController
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
redirect_to characters_path, notice: 'Character was created'
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)
redirect_to characters_path, notice: 'Character was updated'
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
redirect_to characters_path, notice: 'Character was deleted'
end
private
def character_params
params.require(:character).permit(:name)
end
def set_character
@character = Character.find(params[:id])
end
end