Skip to content

Commit

Permalink
Merge branch 'dev' into testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Uthmanbello authored May 25, 2023
2 parents 43ad944 + f465358 commit a98e175
Show file tree
Hide file tree
Showing 27 changed files with 290 additions and 51 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,5 @@ group :test do
gem 'selenium-webdriver'
gem 'webdrivers'
end

gem 'cancancan'
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ GEM
bootsnap (1.16.0)
msgpack (~> 1.2)
builder (3.2.4)
cancancan (3.5.0)
capybara (3.39.1)
addressable
matrix
Expand Down Expand Up @@ -268,6 +269,7 @@ PLATFORMS

DEPENDENCIES
bootsnap
cancancan
capybara
cssbundling-rails
debug
Expand Down
177 changes: 164 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,175 @@
# README
<h2>Recipe-App</h2>
<img src="app/assets/images/cook-book.png" alt="Icon" width="100px" height="100px" />
<br>
<br>

This README would normally document whatever steps are necessary to get the
application up and running.
# 📗 Table of Contents
- [📖 About the Project](#about-project)
- [🛠 Built With](#built-with)
- [Tech Stack](#tech-stack)
- [Key Features](#key-features)
- [💻 Getting Started](#getting-started)
- [Setup](#setup)
- [Prerequisites](#prerequisites)
- [Install](#install)
- [Usage](#usage)
- [Run tests](#run-tests)
- [Deployment](#triangular_flag_on_post-deployment)
- [👥 Authors](#authors)
- [🔭 Future Features](#future-features)
- [🤝 Contributing](#contributing)
- [⭐️ Show your support](#support)
- [🙏 Acknowledgements](#acknowledgements)
- [📝 License](#license)

Things you may want to cover:
# 📖 Recipe-App <a name="about-project"></a>
Recipe App is a robust and user-friendly recipe application built using Ruby on Rails, leveraging the power of Bootstrap, Devise, and Capybara gems. Seamlessly create, discover, and share recipes with it. It offers a delightful cooking experience with its intuitive interface and extensive features.
**Recipe-App**
## 🛠 Built With <a name="built-with"></a>
PostgresSQL
Ruby on rails
### Tech Stack <a name="tech-stack"></a>

* Ruby version
<details>
<ul>
<li><a href="https://www.ruby-lang.org/en/">Ruby</a></li>
<li><a href="https://rubyonrails.org/">Ruby on rails</a></li>
<li><a href="https://www.postgresql.org/">PSQL</a></li>
</ul>
</details>
<br>

* System dependencies
### Key Features <a name="key-features"></a>
<details>
<ul>
<li>Add Foods with its value and measure unit</li>
<li>Add Recipes with its cooking time and prep time</li>
<li>If recipe is made public by that user than it shows under public recipes page</li>
</ul>
</details>

* Configuration
<p align="right">(<a href="#readme-top">back to top</a>)</p>

* Database creation

* Database initialization
## 💻 Getting Started <a name="getting-started"></a>
<br>

* How to run the test suite
### Prerequisites
<details>
<p>In order to run this project you need:</p>
<ul>
<li>Ruby installed</li>
<li>Add Recipes with its cooking time and prep time</li>
<li>rbenv installed</li>
</ul>
</details>
<br>

* Services (job queues, cache servers, search engines, etc.)

* Deployment instructions
### Setup

* ...
Clone this repository to your desired folder:

git clone https://github.com/anas599/Recipe-app.git
cd Recipe-App


<br>


### Install


<details>
<p>Install this project with:</p>
<ul>
<li> cd Recipe-app</li>
<li> run rails server</li>
</ul>
</details>
<br>


### Usage
<details>
<p>To run the project, execute the following command:</p>
<ul>
<li> cd Recipe-app</li>
<li> run rails server</li>
</ul>
</details>
<br>



### Run tests
<details>
<p>To run tests, run the following command:</p>
<ul>
<li>rspec</li>
</ul>
</details>
<br>


### Deployment
<details>
<p>You can deploy this project using:</p>
<ul>
<li>Heroku</li>
</ul>
</details>
<br>

<p align="right">(<a href="#readme-top">back to top</a>)</p>👥 Authors <a name="authors"></a>

👤 **ANAS ALSAMMARRAIE**

- GitHub: [@anas599](https://github.com/anas599)
- Twitter: [@anas599](https://twitter.com/anas599)
- LinkedIn: [anas1993](https://linkedin.com/in/anas1993)


<p align="right">(<a href="#readme-top">back to top</a>)</p>


## 🔭 Future Features <a name="future-features"></a>
<details>
<ul>
<li>Add videos for new data</li>
<li>Add images of food</li>
<li>Update style</li>
</ul>
</details>
<br>


<p align="right">(<a href="#readme-top">back to top</a>)</p>


## 🤝 Contributing <a name="contributing"></a>

Contributions, issues, and feature requests are welcome!

Feel free to check the [issues page](../../issues/).


<p align="right">(<a href="#readme-top">back to top</a>)</p>

## ⭐️ Show your support <a name="support"></a>

> If you like the project Please do not hesitate if you have any questions
<p align="right">(<a href="#readme-top">back to top</a>)</p>

## 🙏 Acknowledgments <a name="acknowledgements"></a>

> I would like to thank Microverse for this project based learning
<p align="right">(<a href="#readme-top">back to top</a>)</p>

## 📝 License <a name="license"></a>

This project is [MIT](./LICENSE) licensed.

<p align="right">(<a href="#readme-top">back to top</a>)</p>
6 changes: 3 additions & 3 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up, keys: %i[email name password password_confirmation])
end

def set_current_user
@current_user = current_user
end
# def set_current_user
# @current_user = current_user
# end

def after_sign_in_path_for(resource)
flash[:notice] = "Welcome back, #{resource.name}!"
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/foods_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,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_path, notice: 'Food was successfully created.' }
format.json { render :show, status: :created, location: @food }
else
format.html { render :new, status: :unprocessable_entity }
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/public_recipes_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class PublicRecipesController < ApplicationController
def index
@public_recipes = Recipe.where(public: true)
@public_recipes = Recipe.where(public: true).order(created_at: :desc)
end
end
3 changes: 2 additions & 1 deletion app/controllers/recipes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ class RecipesController < ApplicationController

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

# GET /recipes/1 or /recipes/1.json
def show
@recipe = Recipe.find(params[:id])
@recipe_foods = @recipe.recipe_foods
authorize! :read, @recipes
end

# GET /recipes/new
Expand Down
36 changes: 36 additions & 0 deletions app/models/ability.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
class Ability
include CanCan::Ability

def initialize(user)
# Define abilities for the user here. For example:
#
# return unless user.present?
# can :read, :all
# return unless user.admin?
# can :manage, :all
#
# The first argument to `can` is the action you are giving the user
# permission to do.
# If you pass :manage it will apply to every action. Other common actions
# here are :read, :create, :update and :destroy.
#
# The second argument is the resource the user can perform the action on.
# If you pass :all it will apply to every resource. Otherwise pass a Ruby
# class of the resource.
#
# The third argument is an optional hash of conditions to further filter the
# objects.
# For example, here the user can only update published articles.
#
# can :update, Article, published: true
#
# See the wiki for details:
# https://github.com/CanCanCommunity/cancancan/blob/develop/docs/define_check_abilities.md

user ||= User.new

can :read, :all
can :manage, Food, user_id: user.id
can :manage, Recipe, user_id: user.id
end
end
4 changes: 4 additions & 0 deletions app/models/food.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
class Food < ApplicationRecord
belongs_to :user
validates :name, presence: true
validates :measure_unit, presence: true, inclusion: { in: %w[Gram Pound Unit] }
validates :price, presence: true, numericality: { only_integer: true }
validates :quantity, presence: true, numericality: { only_integer: true }
end
4 changes: 4 additions & 0 deletions app/models/recipe.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
class Recipe < ApplicationRecord
belongs_to :user
has_many :recipe_foods
validates :name, presence: true
validates :description, presence: true
validates :cooking_time, presence: true, numericality: { only_integer: true }
validates :prep_time, presence: true, numericality: { only_integer: true }
end
7 changes: 7 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,11 @@ class User < ApplicationRecord
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable

validates :email, presence: true
validates :password, presence: true
validates :password_confirmation, presence: true
validates :email, length: { maximum: 30 }
validates :password, length: { in: 6..20 }
validates :email, presence: true, uniqueness: true
end
3 changes: 1 addition & 2 deletions app/views/foods/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<section class="container">
<p style="color: green"><%= notice %></p>
<h1 class="mb-5">Foods for user: <%=current_user.name%></h1>
<h1 class="mb-5">Foods for user: <%=current_user.name%></h1>
<table class="table table-striped table-hover ">
<tr>
<th class="text-center" scope="col">Food</th>
Expand Down
1 change: 0 additions & 1 deletion app/views/foods/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<p style="color: green"><%= notice %></p>

<%= render @food %>

Expand Down
15 changes: 8 additions & 7 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@
<meta name="viewport" content="width=device-width,initial-scale=1">
<%= csrf_meta_tags %>
<%= csp_meta_tag %>

<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= stylesheet_link_tag 'custom', 'data-turbo-track': 'reload' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css">
</head>
<%=render "shared/navbar"%>

<body>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>

<div class="container">
<%= yield %>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
<div class="container">
<% flash.each do |key, value| %>
<div class="alert <%= bootstrap_alert_class(key) %> alert-dismissible fade show" role="alert">
<%= value %>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<% end %> <%= yield %>
</div>

</body>
</html>
2 changes: 1 addition & 1 deletion app/views/public_recipes/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div class="shadow p-3 mb-5 bg-white rounded container">
<div class="row">
<% user = User.find(x.user_id) %>
<h4 class="col-6 text-center"><%= x.name %></h4>
<h4 class="col-6 text-center"><%= link_to x.name, x %></h4>
<% recipe_foods = RecipeFood.where(recipe_id: x.id) %>
<% total_price = 0 %>
<% recipe_foods.each do |recipe_food| %>
Expand Down
1 change: 0 additions & 1 deletion app/views/recipe_foods/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<p style="color: green"><%= notice %></p>

<h1>Recipe foods</h1>

Expand Down
1 change: 0 additions & 1 deletion app/views/recipe_foods/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<p style="color: green"><%= notice %></p>

<%= render @recipe_food %>

Expand Down
Loading

0 comments on commit a98e175

Please sign in to comment.