diff --git a/app/models/unit.rb b/app/models/unit.rb index 4f50405..f466809 100644 --- a/app/models/unit.rb +++ b/app/models/unit.rb @@ -4,14 +4,17 @@ class Unit < ApplicationRecord belongs_to :user, optional: true belongs_to :base, optional: true, class_name: "Unit" - validates :symbol, presence: true, uniqueness: {scope: :user_id} + validates :symbol, presence: true, uniqueness: {scope: :user_id}, + length: {maximum: columns_hash['symbol'].limit} + validates :name, length: {maximum: columns_hash['name'].limit} validates :multiplier, numericality: {equal_to: 1}, unless: :base validates :multiplier, numericality: {other_than: 1}, if: :base validate if: -> { base.present? } do errors.add(:base, :only_top_level_base_units) unless base.base.nil? end - acts_as_nested_set parent_column: :base_id, scope: :user, dependent: :destroy, order_column: :multiplier + acts_as_nested_set parent_column: :base_id, scope: :user, dependent: :destroy, + order_column: :multiplier scope :defaults, -> { where(user: nil) } diff --git a/app/views/units/_form.html.erb b/app/views/units/_form.html.erb index 014a937..50a8cec 100644 --- a/app/views/units/_form.html.erb +++ b/app/views/units/_form.html.erb @@ -1,10 +1,11 @@ <%= fields_for unit do |form| %>