tabletop-companion/app/controllers/dice_rolls_controller.rb

28 lines
602 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])
@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