summaryrefslogtreecommitdiff
path: root/app/controllers/characters/titles_controller.rb
blob: b321af9966c463799a713974759375ab6cafea72 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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