From a3cd17182ee15e99788dfd9c3495351d36e6302c Mon Sep 17 00:00:00 2001 From: Adrienne Yao Date: Tue, 28 Jan 2020 16:34:10 +0000 Subject: [PATCH] Done. --- Gemfile.lock | 9 +--- app/controllers/application_controller.rb | 44 +++++++++++++++++++- app/models/recipe.rb | 5 ++- app/views/edit.erb | 14 +++++++ app/views/index.erb | 10 +++++ app/views/new.erb | 14 +++++++ app/views/show.erb | 8 ++++ db/development.sqlite | Bin 0 -> 5120 bytes db/migrate/20200128161227_create_recipes.rb | 9 ++++ db/schema.rb | 22 ++++++++++ db/test.sqlite | Bin 0 -> 5120 bytes 11 files changed, 126 insertions(+), 9 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/20200128161227_create_recipes.rb create mode 100644 db/schema.rb diff --git a/Gemfile.lock b/Gemfile.lock index 7d1a42a53f..3928b583e4 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.7.0) 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..18a080013d 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,9 +1,51 @@ +require './config/environment' + class ApplicationController < Sinatra::Base + # register Sinatra::ActiveRecordExtension + set :views, Proc.new { File.join(root, "../views/") } + configure do set :public_folder, 'public' set :views, 'app/views' end - # code actions here! + get '/recipes/new' do #loads new form + erb :new + end + + get '/recipes' do #loads index page + @recipes = Recipe.all + erb :index + end + + get '/recipes/:id' do #loads show page + @recipe = Recipe.find_by_id(params[:id]) + erb :show + end + + get '/recipes/:id/edit' do #loads edit form + @recipe = Recipe.find_by_id(params[:id]) + erb :edit + end + + patch '/recipes/:id' do #updates a recipe + @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 #creates a recipe + @recipe = Recipe.create(params) + redirect to "/recipes/#{@recipe.id}" + end + + delete '/recipes/:id' do #destroy action + @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..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/edit.erb b/app/views/edit.erb new file mode 100644 index 0000000000..c2fb5359e6 --- /dev/null +++ b/app/views/edit.erb @@ -0,0 +1,14 @@ +
+ + + + + + + + + + + + +
diff --git a/app/views/index.erb b/app/views/index.erb index e69de29bb2..c9c1cf61e0 100644 --- a/app/views/index.erb +++ b/app/views/index.erb @@ -0,0 +1,10 @@ + + diff --git a/app/views/new.erb b/app/views/new.erb new file mode 100644 index 0000000000..b7ac3d91a5 --- /dev/null +++ b/app/views/new.erb @@ -0,0 +1,14 @@ + +
+ + + + + + + + + + + +
diff --git a/app/views/show.erb b/app/views/show.erb new file mode 100644 index 0000000000..be76cc65b4 --- /dev/null +++ b/app/views/show.erb @@ -0,0 +1,8 @@ +Name: <%= @recipe.name %> +Ingredients: <%= @recipe.ingredients %> +Cook time: <%= @recipe.cook_time %> + +
+ + +
diff --git a/db/development.sqlite b/db/development.sqlite new file mode 100644 index 0000000000000000000000000000000000000000..9a74467d098a49a936ba084f142611237a82bb84 GIT binary patch literal 5120 zcmeH}UrWO<5WthRS``EZWee;@+YMjmNAT15 zsRX})sdlnIOkYKF^hhpEE_c7=Xs<3yJYvxHgRT?79?}rT=okPYqzYXSI+EDdMuuqd zSbttuMZ0e=tKzMuY#{YnT~gYjBjr~UsA`L;?QPtMoSO~{dmV8>nj!1;ndeTM3#T<& zuqoJulM;ogxf##tvK_I~7;dS0DxJnpn;$*{=JE#?CXF`XgCwH_GK9AX6fK*c(;8H3 z#d4w6fD77yLfx(uEwQXjEgP(g(0Zw~10>#%z`zOIJ0}n}_ih8$;>?S}@nP5Z@0$@H zn`;bpMNb`N@i5E17JKY_T;$sf-8ok|0n+HB`Zll5?C4nvj3Ons%4>) Hzzl&;59_zg literal 0 HcmV?d00001