1
0

New objects are now created through association

Added Sources to sidebar
This commit is contained in:
cryptogopher
2019-09-23 15:35:43 +02:00
parent ce9f011694
commit c96cea5ca6
10 changed files with 21 additions and 10 deletions

View File

@@ -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)

View File

@@ -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)

View File

@@ -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

View File

@@ -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)