50 lines
1.1 KiB
Ruby
50 lines
1.1 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
|
||
|
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,
|
||
|
)
|
||
|
end
|
||
|
end
|