tabletop-companion/app/controllers/text_fields_controller.rb

57 lines
1.3 KiB
Ruby
Raw Normal View History

2024-06-14 11:59:35 +00:00
# frozen_string_literal: true
class TextFieldsController < ApplicationController
before_action :set_section, only: [ :new, :create ]
before_action :set_character, only: [ :new, :create ]
2024-06-21 09:57:03 +00:00
before_action :set_text_field, only: [ :show, :update, :destroy ]
2024-06-14 11:59:35 +00:00
def new
@text_field = @section.text_fields.new
2024-06-17 13:53:09 +00:00
@text_field.build_character_sheet_feature
2024-06-14 11:59:35 +00:00
end
def create
@text_field = @section.text_fields.new(text_field_params)
@editable = true
unless @text_field.save
render :new, status: :unprocessable_entity
end
end
2024-06-21 09:57:03 +00:00
def show
end
2024-06-14 11:59:35 +00:00
def update
@text_field.update(text_field_params)
end
def destroy
@id = helpers.dom_id(@text_field)
@text_field.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_text_field
@text_field = Current.user.text_fields.find(params[:id])
end
def text_field_params
params.require(:text_field).permit(
:name,
:content,
:character_sheet_section_id,
2024-06-17 13:53:09 +00:00
character_sheet_feature_attributes: [
:id, :featurable_id, :featurable_type, :character_sheet_section_id, :_destroy,
],
2024-06-14 11:59:35 +00:00
)
end
end