From 5e1eb02c0f47427a8db8196e6f9cf64d39976834 Mon Sep 17 00:00:00 2001 From: Ian Gutwinski Date: Fri, 27 Mar 2020 14:50:25 -0400 Subject: [PATCH] Done. --- Gemfile.lock | 11 ++--- app/controllers/application_controller.rb | 43 +++++++++++++++++++- app/models/recipe.rb | 3 +- app/views/edit.erb | 22 ++++++++++ app/views/index.erb | 14 +++++++ app/views/new.erb | 16 ++++++++ app/views/show.erb | 19 +++++++++ db/development.sqlite | Bin 0 -> 20480 bytes db/migrate/20200327172825_create_recipes.rb | 9 ++++ db/schema.rb | 22 ++++++++++ db/test.sqlite | Bin 0 -> 20480 bytes 11 files changed, 149 insertions(+), 10 deletions(-) create mode 100644 app/views/edit.erb create mode 100644 app/views/new.erb create mode 100644 app/views/show.erb create mode 100644 db/development.sqlite create mode 100644 db/migrate/20200327172825_create_recipes.rb create mode 100644 db/schema.rb diff --git a/Gemfile.lock b/Gemfile.lock index 7d1a42a53f..bb0d4d9470 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.3) 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 @@ -125,4 +120,4 @@ DEPENDENCIES tux BUNDLED WITH - 2.0.2 + 2.1.4 diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index a77b95518a..aa588ec0a7 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -4,6 +4,47 @@ class ApplicationController < Sinatra::Base set :views, 'app/views' end - # code actions here! + get '/' do + redirect to "/recipes" + end + + get '/recipes' do + erb :index + end + + get '/recipes/new' do + erb :new + end + + + get '/recipes/:id' do + @recipe = Recipe.find_by_id(params[:id]) + erb :show + end + + get '/recipes/:id/edit' do + @recipe = Recipe.find_by_id(params[:id]) + erb :edit + end + + patch '/recipes/:id' do + @recipe = Recipe.find_by_id(params[:id]) + @recipe.name = params[:name] + @recipe.ingredients = params[:ingredients] + @recipe.cook_time = params[:cook_time] + @recipe.save + redirect to "/recipes/#{@recipe.id}" + end + + post '/recipes' do + @recipe = Recipe.create(:name => params[:name], :ingredients => params[:ingredients], :cook_time => params[:cook_time]) + redirect to "/recipes/#{@recipe.id}" + end + + delete '/recipes/:id' do + @recipe = Recipe.find_by_id(params[:id]) + @recipe.delete + redirect to '/recipes' + end end diff --git a/app/models/recipe.rb b/app/models/recipe.rb index 2677f6e06b..34908d5e08 100644 --- a/app/models/recipe.rb +++ b/app/models/recipe.rb @@ -1 +1,2 @@ -#Placeholder for a model \ No newline at end of file +class Recipe < ActiveRecord::Base +end \ No newline at end of file diff --git a/app/views/edit.erb b/app/views/edit.erb new file mode 100644 index 0000000000..98543dfbcb --- /dev/null +++ b/app/views/edit.erb @@ -0,0 +1,22 @@ + + + +Edit Recipe Form + + +

Here is The Selected Recipe

+

Recipe No. <%= @recipe.id %>

+

Recipe Name: <%= @recipe.name %>

+

Ingredients: <%= @recipe.ingredients %>

+

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

+ +

Enter Your Updated Recipe Info Here: for Recipe No. <%= @recipe.id %>

+
+ +

New Recipe Name:

+

New Recipe Ingredients:

+

New Recipe Cook Time:

+ +
+ + \ No newline at end of file diff --git a/app/views/index.erb b/app/views/index.erb index e69de29bb2..38ce4f1ef8 100644 --- a/app/views/index.erb +++ b/app/views/index.erb @@ -0,0 +1,14 @@ + + + + + +

Here are Gramdma's Recipes

+<% @recipes = Recipe.all %> +<% @recipes.each do |x| %> +

<%= x.name %>

+<% end %> + +

To add a new recipe, click here

+ + \ No newline at end of file diff --git a/app/views/new.erb b/app/views/new.erb new file mode 100644 index 0000000000..dbad55df62 --- /dev/null +++ b/app/views/new.erb @@ -0,0 +1,16 @@ + + + +New Recipe Form + + +

New Recipe Form

+

Enter Your New Recipe Info Here:

+
+

Recipe Name:

+

Recipe Ingredients:

+

Recipe Cook Time:

+ +
+ + \ No newline at end of file diff --git a/app/views/show.erb b/app/views/show.erb new file mode 100644 index 0000000000..475c7dc531 --- /dev/null +++ b/app/views/show.erb @@ -0,0 +1,19 @@ + + + +Recipe Display + + +

Here is The Selected Recipe

+

Recipe No. <%= @recipe.id %>

+

Recipe Name: <%= @recipe.name %>

+

Ingredients: <%= @recipe.ingredients %>

+

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

+ +
+ + +
+ + + \ No newline at end of file diff --git a/db/development.sqlite b/db/development.sqlite new file mode 100644 index 0000000000000000000000000000000000000000..8ecefb7d3cd751f349408161907ed48f93d003e0 GIT binary patch literal 20480 zcmeI)(Qnc~90%|_3W6Hfnaz*|6VDnG8i+6!GJP-+u`xs_8$u#aq?X%yfwr#gHhsi5 zU;R6L@UQWoF!5#ofX65XHm6TBX8B&Y^mo_0U++GBx}@RtZc{{@?fHRgMQn?#5=zN4 z#t0!9SyQskiz0*Mydkf2A-*WgkVkjF-ja8dE9*r4tY%jBWPkzz2tWV=5P$##AOHaf zKmY>&g}_eoTDDN2{m6Pd=HbCu9uNm1KRD!`eYTmZcZ^!sVBOmDroqmP&3l&1i*lwu zxu>MFxg7m?=QL-)ZSjtW@g=#GLyLPgme<5kV-2%wyfiv&r_*TFI(_!a=(Ad{+isY0 zTFWrI%xufrYc`8an?6uuM^<1vRv_EL+Yk6qa4!lMyKUbe4I;5HR-dF3>Fm=Ios@(( z1;_ZBt7H*>k1Ofe1A+nr}<^3PtWF5{Xygp1p*L&00bZa0SG_<0uX=z1Rwx` zDjp zzI^^a{Wf3yMAYx z;&?O-M}CpH;&}YT6<(NEQbaFo)E!}uIA?W-^N`P4UNLS~!v literal 0 HcmV?d00001 diff --git a/db/migrate/20200327172825_create_recipes.rb b/db/migrate/20200327172825_create_recipes.rb new file mode 100644 index 0000000000..4530c0c48c --- /dev/null +++ b/db/migrate/20200327172825_create_recipes.rb @@ -0,0 +1,9 @@ +class CreateRecipes < ActiveRecord::Migration + def change + create_table :recipes do |t| + t.string :name + t.string :ingredients + t.string :cook_time + end + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000000..00ea6de597 --- /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: 20200327172825) do + + create_table "recipes", force: :cascade do |t| + t.string "name" + t.string "ingredients" + t.string "cook_time" + end + +end diff --git a/db/test.sqlite b/db/test.sqlite index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..bd64ab7246a0c54a0e489a2e9606191d2d38aff8 100644 GIT binary patch literal 20480 zcmeI&(QDH{9Ki9U?TiYx6DEC_;Bik28@6W1d=ab~q}ZifO~F2unBKO-Hr>WOJk5I_I{1Q0*~0R#|0009L43xT7` zo%-&sJ;f77) z*GIqBOjWGURaTrTD{IJNREiy`M^dzd(0}Lm#8Iz(*y;_$dw(EW{jl2(%(O#42u08} zwcqLN2|0hD6jxCipGB$Z>*O?5BdwA=TON+5)6c_PFWu|ToRU+2*|28~os86%%S4-a zhgp24Ced)BPtz#Z(rc2QcguJoHJk~3fX66af9otU5 zVK(CY=KtpoN~?T-U3@|F$IPAQ=63CeWey4g2q1s}0tg_000IagfB*srtcAd)U2?sq z*KF>42hR??7vA&xCNA>-wRpJ%fdB#sAbz2@Dp)jx1s<5 literal 0 HcmV?d00001