Skip to content

Commit

Permalink
update and add devise
Browse files Browse the repository at this point in the history
  • Loading branch information
anas599 committed May 22, 2023
1 parent 973b396 commit 2262f79
Show file tree
Hide file tree
Showing 87 changed files with 1,998 additions and 143 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', require: false
gem 'devise'
gem 'rubocop', '>= 1.0', '< 2.0'
# Use Sass to process CSS
# gem "sassc-rails"
Expand Down
14 changes: 14 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ GEM
addressable (2.8.4)
public_suffix (>= 2.0.2, < 6.0)
ast (2.4.2)
bcrypt (3.1.18)
bindex (0.8.1)
bootsnap (1.16.0)
msgpack (~> 1.2)
Expand All @@ -90,6 +91,12 @@ GEM
debug (1.8.0)
irb (>= 1.5.0)
reline (>= 0.3.1)
devise (4.9.2)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 4.1.0)
responders
warden (~> 1.2.3)
erubi (1.12.0)
globalid (1.1.0)
activesupport (>= 5.0)
Expand Down Expand Up @@ -130,6 +137,7 @@ GEM
nio4r (2.5.9)
nokogiri (1.15.1-arm64-darwin)
racc (~> 1.4)
orm_adapter (0.5.0)
parallel (1.23.0)
parser (3.2.2.1)
ast (~> 2.4.1)
Expand Down Expand Up @@ -172,6 +180,9 @@ GEM
regexp_parser (2.8.0)
reline (0.3.4)
io-console (~> 0.5)
responders (3.1.0)
actionpack (>= 5.2)
railties (>= 5.2)
rexml (3.2.5)
rubocop (1.51.0)
json (~> 2.3)
Expand Down Expand Up @@ -209,6 +220,8 @@ GEM
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.4.2)
warden (1.2.9)
rack (>= 2.0.9)
web-console (4.2.0)
actionview (>= 6.0.0)
activemodel (>= 6.0.0)
Expand All @@ -234,6 +247,7 @@ DEPENDENCIES
capybara
cssbundling-rails
debug
devise
jbuilder
jsbundling-rails
pg (~> 1.1)
Expand Down
Binary file added app/assets/images/cook-book.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 11 additions & 1 deletion app/assets/stylesheets/custom.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
h1 {
color: red;
color: rgb(0, 0, 0);
}

td,
th {
border: 1px solid black;
}

.icon-app {
width: 2rem;
margin-right: 0.5rem;
}
17 changes: 17 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,19 @@
class ApplicationController < ActionController::Base
before_action :authenticate_user!
before_action :configure_permitted_parameters, if: :devise_controller?

protected

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 after_sign_in_path_for(resource)
flash[:notice] = "Welcome back, #{resource.name}!"
super
end
end
69 changes: 69 additions & 0 deletions app/controllers/foods_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
class FoodsController < ApplicationController
before_action :set_food, only: %i[show edit update destroy]

# GET /foods or /foods.json
def index
@foods = Food.all
end

# GET /foods/1 or /foods/1.json
def show; end

# GET /foods/new
def new
@food = Food.new
end

# GET /foods/1/edit
def edit; end

# POST /foods or /foods.json
def create
@food = Food.new(food_params)

respond_to do |format|
if @food.save
format.html { redirect_to food_url(@food), notice: 'Food was successfully created.' }
format.json { render :show, status: :created, location: @food }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @food.errors, status: :unprocessable_entity }
end
end
end

# PATCH/PUT /foods/1 or /foods/1.json
def update
respond_to do |format|
if @food.update(food_params)
format.html { redirect_to food_url(@food), notice: 'Food was successfully updated.' }
format.json { render :show, status: :ok, location: @food }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @food.errors, status: :unprocessable_entity }
end
end
end

# DELETE /foods/1 or /foods/1.json
def destroy
@food.destroy

respond_to do |format|
format.html { redirect_to foods_url, notice: 'Food was successfully destroyed.' }
format.json { head :no_content }
end
end

private

# Use callbacks to share common setup or constraints between actions.
def set_food
@food = Food.find(params[:id])
end

# Only allow a list of trusted parameters through.
def food_params
params.require(:food).permit(:name, :measure_unit, :price, :quantity, :user_id)
end
end
69 changes: 69 additions & 0 deletions app/controllers/recipe_foods_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
class RecipeFoodsController < ApplicationController
before_action :set_recipe_food, only: %i[show edit update destroy]

# GET /recipe_foods or /recipe_foods.json
def index
@recipe_foods = RecipeFood.all
end

# GET /recipe_foods/1 or /recipe_foods/1.json
def show; end

# GET /recipe_foods/new
def new
@recipe_food = RecipeFood.new
end

# GET /recipe_foods/1/edit
def edit; end

# POST /recipe_foods or /recipe_foods.json
def create
@recipe_food = RecipeFood.new(recipe_food_params)

respond_to do |format|
if @recipe_food.save
format.html { redirect_to recipe_food_url(@recipe_food), notice: 'Recipe food was successfully created.' }
format.json { render :show, status: :created, location: @recipe_food }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @recipe_food.errors, status: :unprocessable_entity }
end
end
end

# PATCH/PUT /recipe_foods/1 or /recipe_foods/1.json
def update
respond_to do |format|
if @recipe_food.update(recipe_food_params)
format.html { redirect_to recipe_food_url(@recipe_food), notice: 'Recipe food was successfully updated.' }
format.json { render :show, status: :ok, location: @recipe_food }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @recipe_food.errors, status: :unprocessable_entity }
end
end
end

# DELETE /recipe_foods/1 or /recipe_foods/1.json
def destroy
@recipe_food.destroy

respond_to do |format|
format.html { redirect_to recipe_foods_url, notice: 'Recipe food was successfully destroyed.' }
format.json { head :no_content }
end
end

private

# Use callbacks to share common setup or constraints between actions.
def set_recipe_food
@recipe_food = RecipeFood.find(params[:id])
end

# Only allow a list of trusted parameters through.
def recipe_food_params
params.require(:recipe_food).permit(:quantity, :recipe_id, :food_id)
end
end
69 changes: 69 additions & 0 deletions app/controllers/recipes_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
class RecipesController < ApplicationController
before_action :set_recipe, only: %i[show edit update destroy]

# GET /recipes or /recipes.json
def index
@recipes = Recipe.all
end

# GET /recipes/1 or /recipes/1.json
def show; end

# GET /recipes/new
def new
@recipe = Recipe.new
end

# GET /recipes/1/edit
def edit; end

# POST /recipes or /recipes.json
def create
@recipe = Recipe.new(recipe_params)

respond_to do |format|
if @recipe.save
format.html { redirect_to recipe_url(@recipe), notice: 'Recipe was successfully created.' }
format.json { render :show, status: :created, location: @recipe }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @recipe.errors, status: :unprocessable_entity }
end
end
end

# PATCH/PUT /recipes/1 or /recipes/1.json
def update
respond_to do |format|
if @recipe.update(recipe_params)
format.html { redirect_to recipe_url(@recipe), notice: 'Recipe was successfully updated.' }
format.json { render :show, status: :ok, location: @recipe }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @recipe.errors, status: :unprocessable_entity }
end
end
end

# DELETE /recipes/1 or /recipes/1.json
def destroy
@recipe.destroy

respond_to do |format|
format.html { redirect_to recipes_url, notice: 'Recipe was successfully destroyed.' }
format.json { head :no_content }
end
end

private

# Use callbacks to share common setup or constraints between actions.
def set_recipe
@recipe = Recipe.find(params[:id])
end

# Only allow a list of trusted parameters through.
def recipe_params
params.require(:recipe).permit(:name, :prep_time, :cooking_time, :description, :public, :user_id)
end
end
Loading

0 comments on commit 2262f79

Please sign in to comment.