tabletop-companion/app/controllers/stats_controller.rb

42 lines
868 B
Ruby

# frozen_string_literal: true
class StatsController < ApplicationController
before_action :set_section, only: [ :new, :create ]
before_action :set_character, only: [ :new, :create ]
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
def destroy
stat = Current.user.stats.find(params[:id])
@id = helpers.dom_id(stat)
stat.destroy
end
private
def set_character
@character = @section.character
end
def set_section
@section = Current.user.character_sheet_sections.find(params[:character_sheet_section_id])
end
def stat_params
params.require(:stat).permit(
:name,
:value,
:roll_command,
:character_sheet_section_id,
)
end
end