36 lines
751 B
Ruby
36 lines
751 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
|
|
|
|
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
|