1
0

Completed UnitsController#import and Unit index view

This commit is contained in:
cryptogopher
2019-08-22 01:12:37 +02:00
parent 8e7385cdcb
commit e9fc9c6475
7 changed files with 54 additions and 11 deletions

View File

@@ -1,13 +1,10 @@
class UnitsController < ApplicationController
before_action :find_project, only: [:new, :index, :create, :import]
before_action :find_project, only: [:index, :create, :import]
before_action :authorize
def new
@unit = Unit.new
end
def index
@unit = Unit.new
@units = @project.units
end
def create
@@ -17,6 +14,11 @@ class UnitsController < ApplicationController
end
def import
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} })
redirect_to project_units_url(@project)
end
private