Prevent rolling unrollable stats
This commit is contained in:
parent
8e1a16bb06
commit
b136792625
|
@ -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,
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue