Skip to content

Commit

Permalink
Merge pull request #2 from mykovasyl/change-ingredients-array
Browse files Browse the repository at this point in the history
Change ingredients array
  • Loading branch information
mykovasyl committed Feb 22, 2023
2 parents f7acf61 + b7dd1eb commit 813a4ef
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 12 deletions.
46 changes: 46 additions & 0 deletions .byebug_history
Original file line number Diff line number Diff line change
@@ -1,3 +1,49 @@
q
recipe
recipe.update({ingredients: params[:ingredients]})
recipe
params[:ingredients]
skip
recipe
skip
recipe
exit
end
recipe.update(params[:ingredients])
params[:ingredients]
recipe
skip
recipeToDelete.destroy
recipeToDelete = Recipe.find("4")
skip
recipe.update({ingredients: params[:ingredients]})
recipe.update({params[:ingredients]})
recipe.ingredients
recipe.title
recipe.update({ingredients: []})
recipe.update([])
recipe
params[:ingredients]
skip
next
recipe.update({ingredients: [{name: "garlic", amount: 2}, {name: "onion", amount: 3}]})
recipe.update({someName: [{name: "garlic", amount: 2}, {name: "onion", amount: 3}]})
recipe.update([{name: "garlic", amount: 2}, {name: "onion", amount: 3}])
params[:ingredients]
skip
recipe.update(ingredients: ["big soup", "little soup"])
recipe(ingredients: ["big soup", "little soup"])
recipe
skip
params[:sourceURL]
params[:image]
params[:readyIn]
params[:title]
params{:title}
params[:ingredients]
recipe.update({params[:ingredients]})
recipe.update(params[:ingredients])
recipe
skip
params[:ingredients]
Recipe.create(params[:ingredients])
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/recipes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def index

def create
recipe = Recipe.create!(new_recipe_params)
byebug
recipe.update({ingredients: params[:ingredients]})
render json: recipe, status: :accepted
end

Expand Down Expand Up @@ -42,4 +42,4 @@ def find_recipe
Recipe.find(params[:id])
end

end
end
4 changes: 4 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@ class User < ApplicationRecord
has_secure_password

has_many :recipes, dependent: :destroy

validates :username, presence: true, uniqueness: true
validates :password, presence: true
validates :password_confirmation, presence: true

end
7 changes: 6 additions & 1 deletion client/src/components/RandomRecipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,18 @@ function RandomRecipe({ handleAddRecipe }) {
)
.then((resp) => resp.json())
.then((data) => {
let newIngredients = data.recipes[0].extendedIngredients.map(
(ingredient) => {
return `${ingredient.name}: ${ingredient.amount} ${ingredient.unit}`;
}
);
setRecipe({
title: data.recipes[0].title,
readyIn: data.recipes[0].readyInMinutes,
image: data.recipes[0].image,
summary: data.recipes[0].summary,
instructions: data.recipes[0].instructions,
ingredients: data.recipes[0].extendedIngredients,
ingredients: newIngredients,
sourceURL: data.recipes[0].spoonacularSourceUrl,
user_id: null,
});
Expand Down
8 changes: 3 additions & 5 deletions client/src/components/Recipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ function Recipe({ recipe, handleAddRecipe, handleDeleteRecipe }) {
summary,
ingredients,
instructions,
sourceUrl,
sourceURL,
user_id = null,
id = null,
} = recipe;

const mappedIngredients = ingredients.map((ingredient) => (
<li key={ingredient.name}>
{ingredient.name}: {ingredient.amount} {ingredient.unit}
</li>
<li key={ingredient}>{ingredient}</li>
));

function addRecipe() {
Expand Down Expand Up @@ -53,7 +51,7 @@ function Recipe({ recipe, handleAddRecipe, handleDeleteRecipe }) {
<h3>Instructions:</h3>
<div dangerouslySetInnerHTML={{ __html: instructions }} />
<p>
For more information visit: <a href={sourceUrl}>Spoonacular</a>
For more information visit: <a href={sourceURL}>Spoonacular</a>
</p>
</div>
);
Expand Down
3 changes: 1 addition & 2 deletions db/migrate/20230208222115_create_recipes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ def change
t.string :image
t.string :summary
t.string :instructions
t.text :ingredients, array: true, default: []
t.text :sourceURL
t.boolean :liked
t.string :ingredients, array: true, default: []

t.timestamps
end
Expand Down
3 changes: 1 addition & 2 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 813a4ef

Please sign in to comment.