Changed Unit uniqueness condtions to shortname only
This commit is contained in:
parent
b0a02b7474
commit
b1be5e571a
@ -27,9 +27,10 @@ class UnitsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def import
|
def import
|
||||||
|
available = Unit.where(project: @project).pluck(:shortname)
|
||||||
defaults = Unit.where(project: nil).pluck(:name, :shortname)
|
defaults = Unit.where(project: nil).pluck(:name, :shortname)
|
||||||
missing = defaults - Unit.where(project: @project).pluck(:name, :shortname)
|
defaults.delete_if { |n, s| available.include?(s) }
|
||||||
@project.units.create(missing.map { |n, s| {name: n, shortname: s} })
|
@project.units.create(defaults.map { |n, s| {name: n, shortname: s} })
|
||||||
|
|
||||||
redirect_to project_units_url(@project)
|
redirect_to project_units_url(@project)
|
||||||
end
|
end
|
||||||
|
@ -2,5 +2,6 @@ class Unit < ActiveRecord::Base
|
|||||||
belongs_to :project
|
belongs_to :project
|
||||||
|
|
||||||
validates :project, associated: true
|
validates :project, associated: true
|
||||||
validates :name, :shortname, presence: true, uniqueness: true
|
validates :name, presence: true
|
||||||
|
validates :shortname, presence: true, uniqueness: {scope: :project_id}
|
||||||
end
|
end
|
||||||
|
@ -15,4 +15,4 @@ en:
|
|||||||
index:
|
index:
|
||||||
heading: 'Units'
|
heading: 'Units'
|
||||||
heading_new_unit: 'New unit'
|
heading_new_unit: 'New unit'
|
||||||
heading_import: 'Import'
|
heading_import: 'Import defaults'
|
||||||
|
Reference in New Issue
Block a user