1
0

Started Ingredient#create

This commit is contained in:
cryptogopher
2019-09-14 23:00:31 +02:00
parent faef248449
commit 0dcb13a065
6 changed files with 41 additions and 8 deletions

View File

@@ -9,8 +9,35 @@ class IngredientsController < ApplicationController
end
def create
@ingredient = Ingredient.new(ingredient_params.update(project: @project))
if @ingredient.save
flash[:notice] = 'Created new ingredient'
redirect_to project_ingredients_url(@project)
else
@ingredients = @project.ingredients
render :index
end
end
def destroy
end
private
def ingredient_params
params.require(:ingredient).permit(
:name,
:ref_amount,
:ref_unit_id,
:group,
nutrients_attributes:
[
:id,
:quantity_id,
:amount,
:unit_id,
:_destroy
]
)
end
end