From 88bd4f77db3a4372c118a9faef613615db66bc52 Mon Sep 17 00:00:00 2001 From: David Gay Date: Sat, 22 May 2021 14:32:38 -0400 Subject: Titles --- app/controllers/characters/titles_controller.rb | 26 +++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 app/controllers/characters/titles_controller.rb (limited to 'app/controllers') 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 -- cgit v1.2.3