1
0
This repository has been archived on 2023-12-07. You can view files and clone it, but cannot push or open issues or pull requests.
body_tracking/app/controllers/units_controller.rb

34 lines
774 B
Ruby

class UnitsController < ApplicationController
before_action :find_project, only: [:index, :create, :import]
before_action :authorize
def index
@unit = Unit.new
@units = @project.units
end
def create
end
def destroy
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
# :find_* methods are called before :authorize,
# @project is required for :authorize to succeed
def find_project
@project = Project.find(params[:project_id])
rescue ActiveRecord::RecordNotFound
render_404
end
end