Changed Unit.type -> .group
Added Unit validations. Added default Units.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
module UnitsHelper
|
||||
def type_options
|
||||
translations = t('.types')
|
||||
Unit.types.map { |k,v| [translations[k.to_sym], k] }
|
||||
def group_options
|
||||
translations = t('.groups')
|
||||
Unit.groups.map { |k,v| [translations[k.to_sym], k] }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
class Unit < ActiveRecord::Base
|
||||
belongs_to :project
|
||||
|
||||
# https://en.wikipedia.org/wiki/International_System_of_Units
|
||||
enum type: {
|
||||
enum group: {
|
||||
number: 0,
|
||||
share: 1,
|
||||
|
||||
@@ -21,4 +23,8 @@ class Unit < ActiveRecord::Base
|
||||
|
||||
pressure: 40
|
||||
}
|
||||
|
||||
validates :project, associated: true
|
||||
validates :name, :shortname, presence: true
|
||||
validates :group, inclusion: groups.keys
|
||||
end
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<p><%= f.text_field :shortname, required: true, size: 10 %></p>
|
||||
</div>
|
||||
<div class="splitcontentright">
|
||||
<p><%= f.select :type, type_options, required: true %></p>
|
||||
<p><%= f.select :group, group_options, required: true %></p>
|
||||
</div>
|
||||
</div>
|
||||
<p><%= f.text_field :name, required: true, size: 40 %></p>
|
||||
|
||||
Reference in New Issue
Block a user