Preliminary MealsController#create
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user