summaryrefslogtreecommitdiff
path: root/app/controllers/characters
diff options
context:
space:
mode:
authorDavid Gay <david@davidgay.org>2021-05-22 14:32:38 -0400
committerDavid Gay <david@davidgay.org>2021-05-22 14:32:44 -0400
commit88bd4f77db3a4372c118a9faef613615db66bc52 (patch)
treec0ad67b0cdde98e58199052198c9b4f1c45a85f2 /app/controllers/characters
parent2dd5608409f0a506cd2a682107d9be302cec8079 (diff)
Titles
Diffstat (limited to 'app/controllers/characters')
-rw-r--r--app/controllers/characters/titles_controller.rb26
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