tabletop-companion/app/controllers/counters_controller.rb

53 lines
1.2 KiB
Ruby
Raw Normal View History

2024-06-12 16:51:57 +00:00
# frozen_string_literal: true
class CountersController < ApplicationController
before_action :set_section, only: [ :new, :create ]
before_action :set_character, only: [ :new, :create ]
before_action :set_counter, only: [ :update, :destroy ]
def new
@counter = @section.counters.new
2024-06-17 13:53:09 +00:00
@counter.build_character_sheet_feature
2024-06-12 16:51:57 +00:00
end
def create
@counter = @section.counters.new(counter_params)
2024-06-14 11:59:35 +00:00
@editable = true
2024-06-12 16:51:57 +00:00
unless @counter.save
render :new, status: :unprocessable_entity
end
end
def update
@counter.update(counter_params)
end
def destroy
@id = helpers.dom_id(@counter)
@counter.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_counter
@counter = Current.user.counters.find(params[:id])
end
def counter_params
params.require(:counter).permit(
:name,
:value,
2024-06-17 13:53:09 +00:00
character_sheet_feature_attributes: [
:id, :featurable_id, :featurable_type, :character_sheet_section_id, :_destroy,
],
2024-06-12 16:51:57 +00:00
)
end
end