-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from tsheporamantso/recipe-list
Recipe list π¨βπ»
- Loading branch information
Showing
12 changed files
with
181 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
.container { | ||
align-items: center; | ||
text-align: center; | ||
} | ||
|
||
.recipe-container { | ||
display: flex; | ||
justify-content: space-around; | ||
align-items: center; | ||
border: 1px solid #333; | ||
padding: 10px; | ||
margin: 0 80px; | ||
} | ||
|
||
.recipe-info { | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: flex-start; | ||
gap: 20px; | ||
} | ||
|
||
p { | ||
font-size: 20px; | ||
font-weight: 700; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
class RecipesController < ApplicationController | ||
def index | ||
@user = User.find(params[:user_id]) | ||
@recipes = @user.recipes | ||
end | ||
|
||
def show | ||
@user = current_user | ||
@recipe = Recipe.find(params[:id]) | ||
end | ||
|
||
def new | ||
@user = current_user | ||
@recipe = @user.recipes.build | ||
end | ||
|
||
def create | ||
@recipe = current_user.recipes.build(recipe_params) | ||
if @recipe.save | ||
redirect_to user_recipes_path(current_user) | ||
else | ||
render :new, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
def destroy | ||
@recipe = current_user.recipes.find(params[:id]) | ||
@recipe.destroy | ||
redirect_to user_recipes_path(current_user), notice: 'Recipe was successfully deleted.' | ||
end | ||
|
||
private | ||
|
||
def recipe_params | ||
params.require(:recipe).permit(:name, :description, :preparation_time, :cooking_time, :public) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module RecipesHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<%= stylesheet_link_tag 'recipe' %> | ||
|
||
<div class="container"> | ||
<h1>Recipes!</h1> | ||
<% @recipes.each do |recipe| %> | ||
<div class='recipe-container'> | ||
<div class="recipe-info"> | ||
<%= link_to recipe.name, user_recipe_path(@user, recipe) %> | ||
<%= button_to 'Remove', user_recipe_path(@user, recipe), data: { | ||
turbo_method: :delete, | ||
turbo_confirm: 'Are you sure?' | ||
} %> | ||
</div> | ||
<div> | ||
<p><%= recipe.description %></p> | ||
</div> | ||
</div> | ||
<%= link_to 'New Recipe', new_user_recipe_path(@user) %> | ||
<% end %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<%= stylesheet_link_tag 'registration' %> | ||
|
||
<div class="container"> | ||
<h1>Create your recipe</h1> | ||
|
||
<%= form_with(model: @recipe, url:user_recipes_path(@user), local: true, method: :post) do |form| %> | ||
<div> | ||
<%= form.label :name %><br> | ||
<%= form.text_field :name, class: 'input'%> | ||
</div> | ||
|
||
<div> | ||
<%= form.label :description %><br> | ||
<%= form.text_area :description, class: 'input' %> | ||
</div> | ||
|
||
<div> | ||
<%= form.label :preparation_time %><br> | ||
<%= form.text_field :preparation_time, class: 'input' %> | ||
</div> | ||
|
||
<div> | ||
<%= form.label :cooking_time %><br> | ||
<%= form.text_field :cooking_time, class: 'input' %> | ||
</div> | ||
|
||
<div> | ||
<%= form.label :public %><br> | ||
<%= form.check_box :public %> | ||
</div> | ||
|
||
<div> | ||
<%= form.submit class: 'btns' %> | ||
</div> | ||
<% end %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<%= stylesheet_link_tag 'recipe' %> | ||
|
||
<div class="container"> | ||
<h1>Recipes</h1> | ||
<div> | ||
<h2><%= @recipe.name %></h2> | ||
</div> | ||
<div class='recipe-info'> | ||
<p>preparation time:<%= @recipe.preparation_time %></p> | ||
<p>cooking time:<%= @recipe.cooking_time %></p> | ||
<p><%= @recipe.description %></p> | ||
</div> | ||
<div> | ||
<%= link_to 'Generate Shopping List' %> | ||
<%= link_to 'Add ingredients' %> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class RemoveUsersIdFromRecipes < ActiveRecord::Migration[7.1] | ||
def change | ||
remove_column :recipes, :users_id | ||
add_reference :recipes, :user, foreign_key: true | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require 'rails_helper' | ||
|
||
# Specs in this file have access to a helper object that includes | ||
# the RecipesHelper. For example: | ||
# | ||
# describe RecipesHelper do | ||
# describe "string concat" do | ||
# it "concats two strings with spaces" do | ||
# expect(helper.concat_strings("this","that")).to eq("this that") | ||
# end | ||
# end | ||
# end | ||
RSpec.describe RecipesHelper, type: :helper do | ||
pending "add some examples to (or delete) #{__FILE__}" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe 'Recipes', type: :request do | ||
describe 'GET /index' do | ||
it 'returns http success' do | ||
get '/recipes/index' | ||
expect(response).to have_http_status(:success) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe 'recipes/index.html.erb', type: :view do | ||
pending "add some examples to (or delete) #{__FILE__}" | ||
end |