diff --git a/app/controllers/counters_controller.rb b/app/controllers/counters_controller.rb index 2f8cb73..239e9c8 100644 --- a/app/controllers/counters_controller.rb +++ b/app/controllers/counters_controller.rb @@ -11,6 +11,7 @@ class CountersController < ApplicationController def create @counter = @section.counters.new(counter_params) + @editable = true unless @counter.save render :new, status: :unprocessable_entity end diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index e8fb0ff..f08d448 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -11,6 +11,7 @@ class StatsController < ApplicationController def create @stat = @section.stats.new(stat_params) + @editable = true unless @stat.save render :new, status: :unprocessable_entity end diff --git a/app/controllers/text_fields_controller.rb b/app/controllers/text_fields_controller.rb new file mode 100644 index 0000000..d56d024 --- /dev/null +++ b/app/controllers/text_fields_controller.rb @@ -0,0 +1,49 @@ +# 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 diff --git a/app/models/user.rb b/app/models/user.rb index fec6849..bd8766f 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -12,6 +12,7 @@ class User < ApplicationRecord has_many :counters, through: :character_sheet_sections has_many :stats, through: :character_sheet_sections has_many :tables, through: :players + has_many :text_fields, through: :character_sheet_sections has_rich_text :profile has_one_attached :avatar do |attachable| attachable.variant :standard, resize_to_limit: [ 100, 100 ], preprocessed: true diff --git a/app/views/character_sheet_sections/_character_sheet_section.html.erb b/app/views/character_sheet_sections/_character_sheet_section.html.erb index eb6e28c..7164b4a 100644 --- a/app/views/character_sheet_sections/_character_sheet_section.html.erb +++ b/app/views/character_sheet_sections/_character_sheet_section.html.erb @@ -10,6 +10,9 @@
<%= text_field.content %>
+ <% end %> +