1
0

Add child Quantity action added

This commit is contained in:
cryptogopher
2020-02-19 21:24:17 +01:00
parent b7b7401833
commit c774f7745d
8 changed files with 53 additions and 2 deletions

View File

@@ -3,7 +3,8 @@ class QuantitiesController < ApplicationController
before_action :init_session_filters
before_action :find_project_by_project_id, only: [:index, :new, :create, :filter, :parents]
before_action :find_quantity, only: [:edit, :update, :destroy, :move]
before_action :find_quantity, only: [:edit, :update, :destroy, :move,
:new_child, :create_child]
before_action :authorize
def index
@@ -75,6 +76,24 @@ class QuantitiesController < ApplicationController
render :index
end
def new_child
@parent_quantity = @quantity
@quantity = @project.quantities.new
@quantity.domain = @parent_quantity.domain
@quantity.parent = @parent_quantity
@quantity.build_formula
end
def create_child
@quantity = @project.quantities.new(quantity_params)
if @quantity.save
flash[:notice] = 'Created new quantity'
prepare_quantities
else
render :new_child
end
end
private
def init_session_filters