forked from fixin.me/fixin.me
Extend NumericalityValidator to check precision and scale
Use new checks on Unit.multiplier Closes #28
This commit is contained in:
@@ -13,7 +13,7 @@ class Unit < ApplicationRecord
|
||||
length: {maximum: columns_hash['symbol'].limit}
|
||||
validates :description, length: {maximum: columns_hash['description'].limit}
|
||||
validates :multiplier, numericality: {equal_to: 1}, unless: :base
|
||||
validates :multiplier, numericality: {other_than: 0}, if: :base
|
||||
validates :multiplier, numericality: {other_than: 0, precision: true, scale: true}, if: :base
|
||||
|
||||
scope :defaults, ->{ where(user: nil) }
|
||||
scope :defaults_diff, ->{
|
||||
|
||||
@@ -13,7 +13,8 @@
|
||||
<td>
|
||||
<% unless @unit.base.nil? %>
|
||||
<%= form.hidden_field :base_id, form: :unit_form %>
|
||||
<%= form.number_field :multiplier, form: :unit_form, required: true, step: "any",
|
||||
<%= form.number_field :multiplier, form: :unit_form, required: true,
|
||||
step: BigDecimal(10).power(-@unit.class.type_for_attribute(:multiplier).scale),
|
||||
size: 10, autocomplete: "off" %>
|
||||
<% end %>
|
||||
</td>
|
||||
|
||||
Reference in New Issue
Block a user