summaryrefslogtreecommitdiff
path: root/app/controllers/characters/items_controller.rb
blob: 8df23c83f814eb316f8ba4abddd5152688048417 (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
class Characters::ItemsController < ApplicationController
  def index
    @character = Character.find(params[:character_id])
  end

  def equip
    @item = Item.find(params[:item_id])
    current_char.equip(@item)
    flash[:notice] = "Equipped #{@item.name}."
  rescue EquipmentError
    flash[:alert] = "Couldn't equip #{@item.name}."
  ensure
    redirect_to character_items_path(current_char)
  end

  def unequip
    current_char.unequip(params[:slot].to_sym)
    flash[:notice] = "Unequipped item."
  rescue EquipmentError
    flash[:alert] = "Couldn't unequip item."
  ensure
    redirect_to character_items_path(current_char)
  end
end