From eda4a43b17dc43b29b2e463cad4cbc954defc3f0 Mon Sep 17 00:00:00 2001 From: Dianne Jarvis-Lumsden Date: Sat, 25 Apr 2020 06:13:40 +0000 Subject: [PATCH 1/2] Done. --- Gemfile.lock | 9 ++------- app/controllers/application_controller.rb | 8 ++++++++ app/models/recipe.rb | 5 ++++- app/views/index.erb | 5 +++++ app/views/show.erb | 0 db/development.sqlite | Bin 0 -> 5120 bytes db/migrate/20200425051557_recipes.rb | 9 +++++++++ db/schema.rb | 22 ++++++++++++++++++++++ db/test.sqlite | Bin 0 -> 5120 bytes 9 files changed, 50 insertions(+), 8 deletions(-) create mode 100644 app/views/show.erb create mode 100644 db/development.sqlite create mode 100644 db/migrate/20200425051557_recipes.rb create mode 100644 db/schema.rb diff --git a/Gemfile.lock b/Gemfile.lock index 7d1a42a53f..d982af8ab9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,9 +1,3 @@ -GIT - remote: https://github.com/bmabey/database_cleaner.git - revision: 85767fa7011355049aa526ffa1f99c6972b98fbf - specs: - database_cleaner (1.8.0) - GEM remote: http://rubygems.org/ specs: @@ -35,6 +29,7 @@ GEM xpath (~> 3.2) coderay (1.1.2) concurrent-ruby (1.1.5) + database_cleaner (1.8.4) diff-lcs (1.3) i18n (0.9.5) concurrent-ruby (~> 1.0) @@ -110,7 +105,7 @@ PLATFORMS DEPENDENCIES activerecord (= 4.2.7.1) capybara - database_cleaner! + database_cleaner json pry pry-nav diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index a77b95518a..d158f26f6a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -5,5 +5,13 @@ class ApplicationController < Sinatra::Base end # code actions here! + get '/recipes' do + @recipes = Recipe.all + erb :index + end + get '/recipes/:id' do + @recipes = Recipe.find_by(params[:id]) + erb :show + end end diff --git a/app/models/recipe.rb b/app/models/recipe.rb index 2677f6e06b..730baf4497 100644 --- a/app/models/recipe.rb +++ b/app/models/recipe.rb @@ -1 +1,4 @@ -#Placeholder for a model \ No newline at end of file +#Placeholder for a model +class Recipe < ActiveRecord::Base + +end diff --git a/app/views/index.erb b/app/views/index.erb index e69de29bb2..f8b2e54dae 100644 --- a/app/views/index.erb +++ b/app/views/index.erb @@ -0,0 +1,5 @@ + + diff --git a/app/views/show.erb b/app/views/show.erb new file mode 100644 index 0000000000..e69de29bb2 diff --git a/db/development.sqlite b/db/development.sqlite new file mode 100644 index 0000000000000000000000000000000000000000..4e4a5228958e3fe5a8c78766fde4a6e36644118d GIT binary patch literal 5120 zcmeH}QBT4!5P;ilIyEuTM8g9QUi!oW21FO1Oq|*nA`Zoo$P<~PLL&^>2Jsbtg1^RJ zW#T`u(_uuSz8dIdm-f2$diS-L?dr13BL=stKzMuY#{YXT~cmEN6Nn@aG@=xvRPb@+?x&y`yFvX8X@ZsnD2cz7mlmc zaws^~QJKQGxf$Q>vYc3HjJ8xgl}_Ww&3B&x^Y}drlSZ5HL6T7d8N!dquNg?wIEOipW>i|4bjcOimI=2&}8d@?`zT-~WlfddW%>kObz2fUN(y MIck}xBrrwb4X;wS*#H0l literal 0 HcmV?d00001 diff --git a/db/migrate/20200425051557_recipes.rb b/db/migrate/20200425051557_recipes.rb new file mode 100644 index 0000000000..70b118edd0 --- /dev/null +++ b/db/migrate/20200425051557_recipes.rb @@ -0,0 +1,9 @@ +class Recipes < ActiveRecord::Migration + def change + create_table :recipes do |t| + t.string :name + t.string :ingredients + t.integer :cook_time + end + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000000..e017439b91 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,22 @@ +# encoding: UTF-8 +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 20200425051557) do + + create_table "recipes", force: :cascade do |t| + t.string "name" + t.string "ingredients" + t.integer "cook_time" + end + +end diff --git a/db/test.sqlite b/db/test.sqlite index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..f70830a750feb320a84fe861ff693e385c93d358 100644 GIT binary patch literal 5120 zcmeH}UrWO<5WthRS``EZWx^gj@?@E^IUPO;P7N}g-5)z}Pos9(3~rsab@)0zf}h4u zCHM`z>L$)HeHBgUk-Idx-2IZHJ+BmHB%sv`x^4tJ#2}QC0{}wE8p;gHsOhK}BLjQ- zNuQ>!k*$}fMSN>$D@1?P=d>0os{LvLWn(sxO3`}cUUo!y+rbOc2*vH4@V&3*%u$u+ z9S%9+&Xl){g~&%<7?cio6& zJXiXWXp6uan3|c`Pt!qK`b}|v=S$4D5qejm>o&Tw9k`L~`QgNXJ`BEQ7b-Q5(H`>) zVAGZ}DA~X!oW!~IMG)c+%<51xk;XvGcl?LjudXH9ube@%Ml1uU@fI1QdaPLqOI4 Nzd34^s3I^y;1%tCxB~zH literal 0 HcmV?d00001 From 2bee66233fad28f2d93d857aa3774460b9d958b3 Mon Sep 17 00:00:00 2001 From: Dianne Jarvis-Lumsden Date: Sat, 25 Apr 2020 23:14:19 +0000 Subject: [PATCH 2/2] Done. --- app/controllers/application_controller.rb | 38 ++++++++++++++++++++-- app/views/edit.erb | 12 +++++++ app/views/index.erb | 3 +- app/views/new.erb | 8 +++++ app/views/show.erb | 10 ++++++ db/development.sqlite | Bin 5120 -> 5120 bytes db/seeds.rb | 5 +++ db/test.sqlite | Bin 5120 -> 5120 bytes 8 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 app/views/edit.erb create mode 100644 app/views/new.erb create mode 100644 db/seeds.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d158f26f6a..e20694b096 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -4,14 +4,46 @@ class ApplicationController < Sinatra::Base set :views, 'app/views' end - # code actions here! + get '/' do + "Vegan Breakface Recipes" + end + + get '/recipes/new' do + erb :new + end + get '/recipes' do @recipes = Recipe.all erb :index - end + end + + post '/recipes' do + @recipe = Recipe.create(params) + redirect to "/recipes/#{@recipe.id}" + end get '/recipes/:id' do - @recipes = Recipe.find_by(params[:id]) + @recipe = Recipe.find_by_id(params[:id]) erb :show end + + get '/recipes/:id/edit' do + @recipe2 = Recipe.find(params[:id]) + erb :edit + end + + patch '/recipes/:id' do + @recipes2 = Article.find(params[:id]) + @recipes2.name = params[:name] + @recipes2.ingredients = params[:ingredients] + @recipes2.cook_time = params[:cook_time] + @recipes2.save + redirect to "/recipes/#{@recipes2.id}" +end + +delete '/recipes/:id' do + @recipe = Recipe.find(params[:id]) + @recipe.delete + redirect to '/recipes' + end end diff --git a/app/views/edit.erb b/app/views/edit.erb new file mode 100644 index 0000000000..8592f22142 --- /dev/null +++ b/app/views/edit.erb @@ -0,0 +1,12 @@ +

Edit the Recipe here...

+

Name: <%= @recipe2.name %>

+

Ingredients: <%= @recipe2.ingredients %>

+

Cook Time: <%= @recipe2.cook_time %>

minutes + +
+ + + + + +
diff --git a/app/views/index.erb b/app/views/index.erb index f8b2e54dae..93f9706287 100644 --- a/app/views/index.erb +++ b/app/views/index.erb @@ -1,5 +1,6 @@ +

List of All Recipes

diff --git a/app/views/new.erb b/app/views/new.erb new file mode 100644 index 0000000000..7acf46067c --- /dev/null +++ b/app/views/new.erb @@ -0,0 +1,8 @@ +
+

Add your Recipe here..

+

Name:

+

Ingredients:

+

Cook Time:

+ + +
diff --git a/app/views/show.erb b/app/views/show.erb index e69de29bb2..88922c0db3 100644 --- a/app/views/show.erb +++ b/app/views/show.erb @@ -0,0 +1,10 @@ + +Here's your <%= @recipe.name %> recipe:

+ +Ingredients: <%= @recipe.ingredients %>
+Cook Time: <%= @recipe.cook_time %> minutes + +
+ + +
diff --git a/db/development.sqlite b/db/development.sqlite index 4e4a5228958e3fe5a8c78766fde4a6e36644118d..f7d19e7cc551796bc3039f729b2c6c78d4c5a342 100644 GIT binary patch delta 203 zcmZqBXwaA-&B!)U#+i|AW5N<{E@tLZ2Ih;*vzbdb3$mm$*Q+qIGN|h_24yCvDg@*g z6=kNRrxpP@Itqz7x%qi13b~m%+2$rptPF;(i~%``nRz8Z3|E?7l$x5SPyiE0(WRlw z$jYE^$>^M4l$V>Dm;=|83>DB(NEXXa&d)0?0ox+S%fP_E$o!ds`SWH$o|nwL+>Ff9 Nj76!*nFXoE%m5`wJ)-~s delta 43 qcmZqBXwaA-&B#1a#+i|MW5N<{CI*(xf&!12Cr*%H<7EH>I2Qo!b_%rs diff --git a/db/seeds.rb b/db/seeds.rb new file mode 100644 index 0000000000..18a4b46a84 --- /dev/null +++ b/db/seeds.rb @@ -0,0 +1,5 @@ +recipe1 = Recipe.create(:name => "Cornmeal Porridge", :ingredients => "cornmeal, coconut milk", :cook_time => 30) + +recipe2 = Recipe.create(:name => "Plaintain Porridge", :ingredients => "green plaintain, almond milk", :cook_time => 40) + +recipe3 = Recipe.create(:name => "Rice Porridge", :ingredients => "rice, almond milk", :cook_time => 55) diff --git a/db/test.sqlite b/db/test.sqlite index f70830a750feb320a84fe861ff693e385c93d358..626bdbeb503f44f798512b5d52b72a68121efd06 100644 GIT binary patch delta 17 YcmZqBXwaA-&FDB$#+lJ^W5NPq04_QOGynhq delta 17 YcmZqBXwaA-%_uQZ#+gxKW5NPq04vi3;s5{u