1
0

Changed Unit uniqueness condtions to shortname only

This commit is contained in:
cryptogopher
2019-08-22 22:10:51 +02:00
parent b0a02b7474
commit b1be5e571a
3 changed files with 6 additions and 4 deletions

View File

@@ -27,9 +27,10 @@ class UnitsController < ApplicationController
end
def import
available = Unit.where(project: @project).pluck(:shortname)
defaults = Unit.where(project: nil).pluck(:name, :shortname)
missing = defaults - Unit.where(project: @project).pluck(:name, :shortname)
@project.units.create(missing.map { |n, s| {name: n, shortname: s} })
defaults.delete_if { |n, s| available.include?(s) }
@project.units.create(defaults.map { |n, s| {name: n, shortname: s} })
redirect_to project_units_url(@project)
end