tabletop-companion/app/controllers/stats_controller.rb

51 lines
1.0 KiB
Ruby
Raw Normal View History

2024-06-07 15:53:32 +00:00
# frozen_string_literal: true
class StatsController < ApplicationController
before_action :set_section, only: [ :new, :create ]
before_action :set_character, only: [ :new, :create ]
2024-06-11 10:37:58 +00:00
before_action :set_stat, only: [ :update, :destroy ]
2024-06-07 15:53:32 +00:00
def new
@stat = @section.stats.new
end
def create
@stat = @section.stats.new(stat_params)
unless @stat.save
render :new, status: :unprocessable_entity
end
end
2024-06-11 10:37:58 +00:00
def update
2024-06-13 16:04:25 +00:00
@editable = true
2024-06-11 10:37:58 +00:00
@stat.update(stat_params)
end
2024-06-10 19:39:46 +00:00
def destroy
2024-06-11 10:37:58 +00:00
@id = helpers.dom_id(@stat)
@stat.destroy
2024-06-10 19:39:46 +00:00
end
2024-06-07 15:53:32 +00:00
private
def set_character
@character = @section.character
end
def set_section
@section = Current.user.character_sheet_sections.find(params[:character_sheet_section_id])
end
2024-06-11 10:37:58 +00:00
def set_stat
@stat = Current.user.stats.find(params[:id])
end
2024-06-07 15:53:32 +00:00
def stat_params
params.require(:stat).permit(
:name,
:value,
:roll_command,
:character_sheet_section_id,
)
end
end