50 lines
1004 B
Ruby
50 lines
1004 B
Ruby
# frozen_string_literal: true
|
|
|
|
class StatsController < ApplicationController
|
|
before_action :set_section, only: [ :new, :create ]
|
|
before_action :set_character, only: [ :new, :create ]
|
|
before_action :set_stat, only: [ :update, :destroy ]
|
|
|
|
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 update
|
|
@stat.update(stat_params)
|
|
end
|
|
|
|
def destroy
|
|
@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 set_stat
|
|
@stat = Current.user.stats.find(params[:id])
|
|
end
|
|
|
|
def stat_params
|
|
params.require(:stat).permit(
|
|
:name,
|
|
:value,
|
|
:roll_command,
|
|
:character_sheet_section_id,
|
|
)
|
|
end
|
|
end
|