tabletop-companion/app/controllers/dice_rolls_controller.rb

30 lines
664 B
Ruby
Raw Normal View History

2024-06-13 16:04:25 +00:00
# frozen_string_literal: true
class DiceRollsController < ApplicationController
before_action :set_table
def create
rollable = dice_roll_params[:rollable_type].constantize.find(dice_roll_params[:rollable_id])
2024-06-14 12:22:24 +00:00
return head :bad_request if rollable.roll_command.blank?
2024-06-13 16:04:25 +00:00
@table.dice_rolls.create!(
rollable:,
result: DiceRoller.new(rollable.roll_command, stat: rollable).roll,
)
head :ok
end
private
def set_table
@table = Current.user.owned_tables.find(params[:table_id])
end
def dice_roll_params
params.require(:dice_roll).permit(
:rollable_type,
:rollable_id,
)
end
end