diff options
Diffstat (limited to 'app/controllers/characters')
-rw-r--r-- | app/controllers/characters/titles_controller.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/app/controllers/characters/titles_controller.rb b/app/controllers/characters/titles_controller.rb new file mode 100644 index 0000000..b321af9 --- /dev/null +++ b/app/controllers/characters/titles_controller.rb @@ -0,0 +1,26 @@ +class Characters::TitlesController < ApplicationController + before_action :set_character + + def index + @title_awards = @character.title_awards + end + + def activate + @title = Title.find(params[:title_id]) + if current_char.title_awards.exists?(title: @title) + current_char.update(active_title: @title) + else + flash[:alert] = "You haven't earned that title." + end + redirect_to character_titles_path(current_char) + end + + private + def set_character + @character = Character.find(params[:character_id]) + unless current_char == @character + flash[:alert] = "You can only look at your own titles." + redirect_to character_path(@character) + end + end +end |