Prevent rolling unrollable stats

This commit is contained in:
Trevor Vallender 2024-06-14 13:22:24 +01:00
parent 8e1a16bb06
commit b136792625
3 changed files with 5 additions and 2 deletions

View File

@ -5,6 +5,8 @@ class DiceRollsController < ApplicationController
def create
rollable = dice_roll_params[:rollable_type].constantize.find(dice_roll_params[:rollable_id])
return head :bad_request if rollable.roll_command.blank?
@table.dice_rolls.create!(
rollable:,
result: DiceRoller.new(rollable.roll_command, stat: rollable).roll,

View File

@ -8,12 +8,14 @@
<%= form_with model: stat, class: "stat-form", data: { controller: "auto-update" } do |f| %>
<%= f.number_field :value %>
<% end %>
<% else %>
<% elsif stat.roll_command.present? %>
<%= form_with model: DiceRoll.new, url: table_dice_rolls_path(stat.character.table), class: "stat-form",
data: { controller: "dice-roll" } do |f| %>
<%= f.hidden_field :rollable_type, value: "Stat" %>
<%= f.hidden_field :rollable_id, value: stat.id %>
<div class="stat-value" data-action="click->dice-roll#rollDice"><%= stat.value %></div>
<% end %>
<% else %>
<div class="stat-value"><%= stat.value %></div>
<% end %>
</div>

View File

@ -1,4 +1,3 @@
- don't roll when no roll set
- set orders on sheets
- easily edit text fields without entering edit mode
- add roll command to counters (e.g. luck)