Skip to content

Commit

Permalink
fix: Food, Recipe, Public Recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
OmarMWarraich committed Feb 19, 2023
1 parent b24dd0f commit 77c83c6
Show file tree
Hide file tree
Showing 14 changed files with 106 additions and 75 deletions.
25 changes: 16 additions & 9 deletions app/assets/stylesheets/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ select {
}

.grid-container {
margin-top: 5rem;
display: grid;
column-gap: var(--container-gap, 2rem);
grid-template-columns: repeat(4, minmax(0, 30rem));
Expand All @@ -141,7 +140,12 @@ select {
font-size: var(--fs-400);
border: 2px solid hsl(var(--clr-white) / 0.1);
border-bottom: none;
padding: 10px 0;
padding: 1rem;
margin-bottom: 0;
}

.grid-container:last-of-type {
border-bottom: 2px solid hsl(var(--clr-white) / 0.1);
}

.sr-only {
Expand Down Expand Up @@ -221,11 +225,8 @@ select {
display: inline-grid;
place-items: center;
text-decoration: none;
}

.small-button {
padding: 0.5rem;
text-decoration: none;
background-color: hsl(var(--clr-light));
color: hsl(var(--clr-dark));
}

.normal-button::after,
Expand All @@ -249,7 +250,7 @@ select {
}

.large-button {
padding: 3rem;
padding: 0.5rem 1.5rem;
}

.normal-button {
Expand Down Expand Up @@ -320,9 +321,15 @@ select {
box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
padding: 20px;
display: grid;
grid-template-columns: 150px 1fr;
grid-template-columns: 200px 300px;
grid-gap: 10px;
align-items: center;
color: white;
font-weight: 100;
place-items: center;
text-decoration: none;
}

.public a {
text-decoration: none;
}
4 changes: 2 additions & 2 deletions app/controllers/foods_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def create

respond_to do |format|
if @food.save
format.html { redirect_to food_url(@food), notice: "Food was successfully created." }
format.html { redirect_to foods_url, notice: "Food was successfully created." }
format.json { render :show, status: :created, location: @food }
else
format.html { render :new, status: :unprocessable_entity }
Expand All @@ -38,7 +38,7 @@ def create
def update
respond_to do |format|
if @food.update(food_params)
format.html { redirect_to food_url(@food), notice: "Food was successfully updated." }
format.html { redirect_to food_url, notice: "Food was successfully updated." }
format.json { render :show, status: :ok, location: @food }
else
format.html { render :edit, status: :unprocessable_entity }
Expand Down
7 changes: 3 additions & 4 deletions app/controllers/public_recipes_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
class PublicRecipesController < ApplicationController
def index
@recipes = Recipe.all
@public_recipes = @recipes.where(public: true)
end
def index
@recipes = Recipe.all.where(public: true)
end
end
4 changes: 2 additions & 2 deletions app/controllers/recipes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class RecipesController < ApplicationController

# GET /recipes or /recipes.json
def index
@recipes = Recipe.all
@recipes = Recipe.all.where(user_id: current_user.id)
end

# GET /recipes/1 or /recipes/1.json
Expand All @@ -25,7 +25,7 @@ def create

respond_to do |format|
if @recipe.save
format.html { redirect_to recipe_url(@recipe), notice: "Recipe was successfully created." }
format.html { redirect_to recipes_url, notice: "Recipe was successfully created." }
format.json { render :show, status: :created, location: @recipe }
else
format.html { render :new, status: :unprocessable_entity }
Expand Down
3 changes: 1 addition & 2 deletions app/views/foods/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
</div>

<div>
<%= form.label :user_id, style: "display: block" %>
<%= form.text_field :user_id %>
<%= form.hidden_field :user_id, value: current_user.id %>
</div>

<div>
Expand Down
30 changes: 22 additions & 8 deletions app/views/foods/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
<p style="color: green"><%= notice %></p>

<h1>Foods</h1>
<h1 class='text-center'>Foods</h1>

<div id="foods">
<div class='container' style='margin-top:2.5rem;'>
<div class='align-left' style='margin-bottom:5rem;'>
<%=link_to "Add Food", new_food_path, class: "large-button" %>
</div>
<ul class='grid-container'>
<li>Food</li>
<li>Measurement Unit</li>
<li>Price</li>
<li>Actions</li>
</ul>
<% @foods.each do |food| %>
<%= render food %>
<p>
<%= link_to "Show this food", food %>
</p>
<% end %>
<ul class='grid-container'>
<li><%= food.name %></li>
<li><%= food.measurement_unit %></li>
<li><%= food.price %></li>
<li>
<%= button_to "Delete", food_path(food.id), method: :delete, class:'large-button' %>
</li>
</ul>
<% end %>
</div>

<%= link_to "New food", new_food_path %>


25 changes: 19 additions & 6 deletions app/views/foods/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
<p style="color: green"><%= notice %></p>

<%= render @food %>
<h1 class='text-center'>Public Recipes</h1>

<div>
<%= link_to "Edit this food", edit_food_path(@food) %> |
<%= link_to "Back to foods", foods_path %>

<%= button_to "Destroy this food", @food, method: :delete %>
<div class='container' style='margin-top:2.5rem;'>
<%= link_to recipe_path(@recipe) do %>
<% @recipes.each do |recipe| %>
<div class='grid'>
<div class='recipe-card'>
<div class='flex-col'>
<%= recipe.name %>
<%= recipe.user.name %>
</div>
<div>
<p>Total Food Items: </p>
<p>Total Price: </p>
</div>
</div>
</div>
<% end %>
<% end %>
</div>

34 changes: 16 additions & 18 deletions app/views/public_recipes/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
<div>
<div class='container'>
<h1 class='text-center' style='margin:3rem 0;'>Public Recipes</h1>
<div class='grid'>
<p style="color: green"><%= notice %></p>

<% @recipes.each do |recipe| %>
<% if recipe.public == true %>
<div class='recipe-card'>
<div class='flex-col'>
<div>
<p><%= recipe.name %></p>
</div>
<div>
<%= link_to 'Delete', recipe_path(recipe), method: :delete, data: { confirm: 'Are you sure?' } %>
<h1 class='text-center'>Public Recipes</h1>

<div class='container public' style='margin-top:2.5rem;'>
<% @recipes.each do |recipe| %>
<%= link_to recipes_url do %>
<div class='grid' style='margin-bottom:2rem;'>
<div class='recipe-card'>
<div class='flex-col'>
<p><%= recipe.name %></p>
<p><%= recipe.user.name %></p>
</div>
<div>
<p>Total Food Items: </p>
<p>Total Price: </p>
</div>
</div>
</div>
<div>
<p><%= recipe.description %></p>
</div>
</div>
<% end %>
<% end %>
</div>
</div>
3 changes: 1 addition & 2 deletions app/views/recipes/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@
</div>

<div>
<%= form.label :user_id, style: "display: block" %>
<%= form.text_field :user_id %>
<%= form.hidden_field :user_id, value: current_user.id %>
</div>

<div>
Expand Down
29 changes: 19 additions & 10 deletions app/views/recipes/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
<p style="color: green"><%= notice %></p>

<h1>Recipes</h1>
<h1 class='text-center'>Recipes</h1>

<div id="recipes">
<% @recipes.each do |recipe| %>
<%= render recipe %>
<p>
<%= link_to "Show this recipe", recipe %>
</p>
<% end %>
<div class='container' style='margin-top:2.5rem;'>
<div class='align-left' style='margin-bottom:5rem;'>
<%=link_to "Add Recipe", new_recipe_path, class: "large-button" %>
</div>
</div>

<%= link_to "New recipe", new_recipe_path %>
<% @recipes.each do |recipe| %>
<div class='recipe-card' style='margin-top:2.5rem;'>
<div>
<h3 style='margin-bottom:0.6rem;'>Recipe <%= recipe.id %></h3>
<%= button_to "Delete", recipe_path(recipe.id), method: :delete, class:'large-button' %>
</div>
<%= link_to recipe_path(recipe.id) do %>
<div>
<p><%= recipe.description %></p>
</div>
<% end %>
</div>
<% end %>

4 changes: 0 additions & 4 deletions app/views/recipes/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,3 @@
<%= render "form", recipe: @recipe %>

<br>

<div>
<%= link_to "Back to recipes", recipes_path %>
</div>
2 changes: 1 addition & 1 deletion app/views/shared/_navbar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<li>
<ul class='primary-navigation underline-indicators'>
<li>
<%= link_to 'Public Recipes' %>
<%= link_to 'Public Recipes', public_recipes_path %>
</li>
<li>
<%= link_to 'Food', foods_path %>
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@


# Defines the root path route ("/")
root "foods#index"
root to: 'public_recipes#index', as: 'public_recipes'
end
9 changes: 3 additions & 6 deletions spec/requests/public_recipes_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
require 'rails_helper'

RSpec.describe 'PublicRecipes', type: :request do
describe 'GET /index' do
it 'returns http success' do
get '/public_recipes/index'
expect(response).to have_http_status(:success)
end
RSpec.describe "PublicRecipes", type: :request do
describe "GET /index" do
pending "add some examples (or delete) #{__FILE__}"
end
end

0 comments on commit 77c83c6

Please sign in to comment.