From b136792625e196b615cb405bfdf5378063ea2ff8 Mon Sep 17 00:00:00 2001 From: Trevor Vallender Date: Fri, 14 Jun 2024 13:22:24 +0100 Subject: [PATCH] Prevent rolling unrollable stats --- app/controllers/dice_rolls_controller.rb | 2 ++ app/views/stats/_stat.html.erb | 4 +++- todo.md | 1 - 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/controllers/dice_rolls_controller.rb b/app/controllers/dice_rolls_controller.rb index 712affa..f0fd4d5 100644 --- a/app/controllers/dice_rolls_controller.rb +++ b/app/controllers/dice_rolls_controller.rb @@ -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, diff --git a/app/views/stats/_stat.html.erb b/app/views/stats/_stat.html.erb index 77465aa..9fea926 100644 --- a/app/views/stats/_stat.html.erb +++ b/app/views/stats/_stat.html.erb @@ -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 %>
<%= stat.value %>
<% end %> + <% else %> +
<%= stat.value %>
<% end %> diff --git a/todo.md b/todo.md index da68a07..a606e9f 100644 --- a/todo.md +++ b/todo.md @@ -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)