tabletop-companion/app/controllers/text_fields_controller.rb

54 lines
1.3 KiB
Ruby

# frozen_string_literal: true
class TextFieldsController < ApplicationController
before_action :set_section, only: [ :new, :create ]
before_action :set_character, only: [ :new, :create ]
before_action :set_text_field, only: [ :update, :destroy ]
def new
@text_field = @section.text_fields.new
@text_field.build_character_sheet_feature
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
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,
character_sheet_feature_attributes: [
:id, :featurable_id, :featurable_type, :character_sheet_section_id, :_destroy,
],
)
end
end