tabletop-companion/app/controllers/templates_controller.rb

48 lines
1.1 KiB
Ruby
Raw Permalink Normal View History

2024-07-02 17:07:06 +00:00
# frozen_string_literal: true
class TemplatesController < ApplicationController
before_action :set_character_sheet_section, only: [ :new ]
before_action :set_template, only: [ :show ]
def new
@template = Template.new
end
def create
@section = CharacterSheetSection.find(template_params[:character_sheet_section_id])
@template = TemplateBuilder.create!(
name: template_params[:name],
from: @section,
game_system: GameSystem.find(template_params[:game_system_id]),
)
if @template.persisted?
redirect_to @template
else
flash.now[:alert] = t(".error")
render :new, status: :unprocessable_entity
end
end
def show
end
private
def set_template
@template = Template.find(params[:id])
end
def set_character_sheet_section
@section = CharacterSheetSection.find(params[:character_sheet_section_id])
end
def template_params
params.require(:template).permit(
:name,
:character_sheet_section_id,
:game_system_id,
:klass,
)
end
end