1
0

Removed Unit.group, added UnitsController#import

This commit is contained in:
cryptogopher
2019-08-21 22:54:13 +02:00
parent fea736bd36
commit 8e7385cdcb
7 changed files with 13 additions and 55 deletions

View File

@@ -1,5 +1,5 @@
class UnitsController < ApplicationController
before_action :find_project, only: [:new, :index, :create]
before_action :find_project, only: [:new, :index, :create, :import]
before_action :authorize
def new
@@ -16,6 +16,9 @@ class UnitsController < ApplicationController
def destroy
end
def import
end
private
# :find_* methods are called before :authorize,

View File

@@ -1,6 +1,2 @@
module UnitsHelper
def group_options
translations = t('.groups')
Unit.groups.map { |k,v| [translations[k.to_sym], k] }
end
end

View File

@@ -1,30 +1,6 @@
class Unit < ActiveRecord::Base
belongs_to :project
# https://en.wikipedia.org/wiki/International_System_of_Units
enum group: {
number: 0,
share: 1,
length: 10,
mass: 11,
time: 12,
temperature: 13,
volume: 20,
density: 21,
ndensity: 22,
frequency: 30,
velocity: 31,
flow: 32,
energy: 30,
pressure: 40
}
validates :project, associated: true
validates :name, :shortname, presence: true
validates :group, inclusion: groups.keys
end

View File

@@ -6,8 +6,7 @@
<p><%= f.text_field :shortname, required: true, size: 10 %></p>
</div>
<div class="splitcontentright">
<p><%= f.select :group, group_options, required: true %></p>
<p><%= f.text_field :name, required: true, size: 40 %></p>
</div>
</div>
<p><%= f.text_field :name, required: true, size: 40 %></p>
</div>