Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions app/controllers/recipes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,41 @@ def create
@recipe.creator = params[:recipe][:creator]
@recipe.submitter = current_user
@recipe.save

params[:Ingredients_recipes].each do | ingredient |
if (Ingredient.find_by(name: ingredient[:name]))
@component = Ingredient.find_by(name: ingredient[:name]))
else
@component = Ingredient.new
@component.name = ingredient[:name]
@component.save
end

ing = Ingredients_recipes.new
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to use model name

ing.amount = Ingredients_recipes[:amount]
ing.measurement = Ingredients_recipes[:measurement]
ing.recipe = @recipe
ing.name = @component
ing.save
end

end

def update
recipe = Recipe.find_by(name: params[:name])
recipe.update(recipe_params)
recipe.save
render json: recipe
end

def delete
recipe = Recipe.find_by(id: params[:recipe_id])
recipe.destroy
end

private
def recipe_params
params.require(:recipe).permit(:name)
end

end