diff --git a/app/controllers/character_sheet_sections_controller.rb b/app/controllers/character_sheet_sections_controller.rb index 47a8975..2340376 100644 --- a/app/controllers/character_sheet_sections_controller.rb +++ b/app/controllers/character_sheet_sections_controller.rb @@ -18,6 +18,7 @@ class CharacterSheetSectionsController < ApplicationController def create @section = @character.character_sheet_sections.new(character_sheet_section_params) + @editable = true unless @section.save @parent_section = @section.parent_section render :new, status: :unprocessable_entity diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index 2b5fb50..b96ac25 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -15,6 +15,12 @@ class StatsController < ApplicationController end end + def destroy + stat = Current.user.stats.find(params[:id]) + @id = helpers.dom_id(stat) + stat.destroy + end + private def set_character @character = @section.character diff --git a/app/models/character.rb b/app/models/character.rb index 8d60aa1..faa8b80 100644 --- a/app/models/character.rb +++ b/app/models/character.rb @@ -5,6 +5,7 @@ class Character < ApplicationRecord belongs_to :game_system belongs_to :user has_many :character_sheet_sections, dependent: :destroy + has_many :stats, through: :character_sheet_sections validates :name, presence: true, length: { maximum: 200 } diff --git a/app/models/user.rb b/app/models/user.rb index 71061c7..97a6154 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -9,6 +9,7 @@ class User < ApplicationRecord has_many :character_sheet_sections, through: :characters has_many :owned_tables, foreign_key: :owner_id, class_name: "Table" has_many :players, dependent: :destroy + has_many :stats, through: :character_sheet_sections has_many :tables, through: :players has_rich_text :profile has_one_attached :avatar do |attachable| diff --git a/app/views/character_sheet_sections/_edit_links.html.erb b/app/views/character_sheet_sections/_edit_links.html.erb index 74cb69c..28eac2f 100644 --- a/app/views/character_sheet_sections/_edit_links.html.erb +++ b/app/views/character_sheet_sections/_edit_links.html.erb @@ -4,7 +4,7 @@ data: { turbo_stream: true } %> <% if section.present? %> <%= link_to t(".add_stat"), - new_character_sheet_section_stat_path(section), data: { turbo_stream: true } %> + new_character_sheet_section_stat_path(section), data: { turbo_stream: true }, class: "add-stat" %> <% end %> <% unless id == "character_sheet_add_section" %> <%= link_to t(".delete_section", name: section.name), character_sheet_section_path(section), diff --git a/app/views/stats/_stat.html.erb b/app/views/stats/_stat.html.erb index 0175048..584b344 100644 --- a/app/views/stats/_stat.html.erb +++ b/app/views/stats/_stat.html.erb @@ -1,4 +1,7 @@