1
0

Preliminary MealsController#create

This commit is contained in:
cryptogopher
2020-04-16 22:02:53 +02:00
parent eb939a1be5
commit ed6b1b9fe7
6 changed files with 39 additions and 7 deletions

View File

@@ -19,6 +19,14 @@ class MealsController < ApplicationController
end
def create
@meal = @project.meals.new(meal_params)
if @meal.save
flash[:notice] = 'Created new meal'
prepare_meals
else
@meal.ingredients.new if @meal.ingredients.empty?
render :new
end
end
def destroy
@@ -26,6 +34,19 @@ class MealsController < ApplicationController
private
def meal_params
params.require(:meal).permit(
:notes,
ingredients_attributes:
[
:id,
:food_id,
:amount,
:_destroy
]
)
end
def prepare_meals
@meals = @project.meals.includes(:foods)
end