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/ingredients_controller.rb
2019-09-14 23:00:31 +02:00

44 lines
884 B
Ruby

class IngredientsController < ApplicationController
before_action :find_project_by_project_id, only: [:index, :create]
before_action :authorize
def index
@ingredient = Ingredient.new
@ingredient.nutrients.build
@ingredients = @project.ingredients
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