From ed0234f158ea5e479ae58a239b9ec6cdcae21055 Mon Sep 17 00:00:00 2001 From: cryptogopher Date: Sat, 4 Jan 2025 15:32:07 +0100 Subject: [PATCH] Allow only positive Unit multiplier Closes #51 --- app/models/unit.rb | 2 +- app/views/units/_form.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/unit.rb b/app/models/unit.rb index 073603c..6aa486e 100644 --- a/app/models/unit.rb +++ b/app/models/unit.rb @@ -13,7 +13,7 @@ class Unit < ApplicationRecord length: {maximum: type_for_attribute(:symbol).limit} validates :description, length: {maximum: type_for_attribute(:description).limit} validates :multiplier, numericality: {equal_to: 1}, unless: :base - validates :multiplier, numericality: {other_than: 0, precision: true, scale: true}, if: :base + validates :multiplier, numericality: {greater_than: 0, precision: true, scale: true}, if: :base scope :defaults, ->{ where(user: nil) } scope :defaults_diff, ->{ diff --git a/app/views/units/_form.html.erb b/app/views/units/_form.html.erb index d298d63..033507f 100644 --- a/app/views/units/_form.html.erb +++ b/app/views/units/_form.html.erb @@ -11,7 +11,7 @@ <% unless @unit.base.nil? %> <%= form.hidden_field :base_id %> - <%= form.number_field :multiplier, required: true, size: 10 %> + <%= form.number_field :multiplier, required: true, size: 10, min: :step %> <% end %>