New objects are now created through association
Added Sources to sidebar
This commit is contained in:
@@ -6,14 +6,15 @@ class IngredientsController < ApplicationController
|
||||
before_action :authorize
|
||||
|
||||
def index
|
||||
@ingredient = Ingredient.new(project: @project)
|
||||
@ingredient = @project.ingredients.new
|
||||
# passing attr for after_initialize
|
||||
@ingredient.nutrients.new(ingredient: @ingredient)
|
||||
@ingredients = @project.ingredients.includes(:ref_unit)
|
||||
@ingredients << @ingredient
|
||||
end
|
||||
|
||||
def create
|
||||
@ingredient = Ingredient.new(ingredient_params.update(project: @project))
|
||||
@ingredient = @project.ingredients.new(ingredient_params)
|
||||
if @ingredient.save
|
||||
flash[:notice] = 'Created new ingredient'
|
||||
redirect_to project_ingredients_url(@project)
|
||||
|
||||
@@ -4,12 +4,12 @@ class QuantitiesController < ApplicationController
|
||||
before_action :authorize
|
||||
|
||||
def index
|
||||
@quantity = Quantity.new
|
||||
@quantity = @project.quantities.new
|
||||
@quantities = @project.quantities
|
||||
end
|
||||
|
||||
def create
|
||||
@quantity = Quantity.new(quantity_params.update(project: @project))
|
||||
@quantity = @project.quantities.new(quantity_params)
|
||||
if @quantity.save
|
||||
flash[:notice] = 'Created new quantity'
|
||||
redirect_to project_quantities_url(@project)
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
class SourcesController < ApplicationController
|
||||
before_action :find_project_by_project_id, only: [:index, :create]
|
||||
before_action :find_source, only: [:destroy]
|
||||
before_action :authorize
|
||||
|
||||
def index
|
||||
@source = @project.sources.new
|
||||
@sources = @project.sources
|
||||
end
|
||||
|
||||
def create
|
||||
|
||||
@@ -4,12 +4,12 @@ class UnitsController < ApplicationController
|
||||
before_action :authorize
|
||||
|
||||
def index
|
||||
@unit = Unit.new
|
||||
@unit = @project.units.new
|
||||
@units = @project.units
|
||||
end
|
||||
|
||||
def create
|
||||
@unit = Unit.new(unit_params.update(project: @project))
|
||||
@unit = @project.units.new(unit_params)
|
||||
if @unit.save
|
||||
flash[:notice] = 'Created new unit'
|
||||
redirect_to project_units_url(@project)
|
||||
|
||||
Reference in New Issue
Block a user