From 0e476dcdcca4433f77ea5cd42591b3055d39a3b3 Mon Sep 17 00:00:00 2001 From: ortufte Date: Thu, 30 Jan 2020 16:01:06 -0600 Subject: [PATCH 1/2] Done. --- Gemfile.lock | 9 +--- app/controllers/application_controller.rb | 43 +++++++++++++++++- app/models/recipe.rb | 3 +- app/views/edit.erb | 23 ++++++++++ app/views/index.erb | 17 +++++++ app/views/new.erb | 22 +++++++++ app/views/show.erb | 16 +++++++ db/development.sqlite | Bin 0 -> 20480 bytes .../20200130192846_create_recipe_table.rb | 9 ++++ db/schema.rb | 22 +++++++++ db/test.sqlite | Bin 0 -> 20480 bytes 11 files changed, 155 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/20200130192846_create_recipe_table.rb create mode 100644 db/schema.rb diff --git a/Gemfile.lock b/Gemfile.lock index 7d1a42a53f..5c67a58785 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.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..87720e00c9 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 '/recipes' + end + + get 'recipes/new' do + erb :new + end + + get '/recipes' do + @recipes = Recipe.all + erb :index + end + + post '/recipes' do + @recipe = Recipe.create(:name => params[:name], :ingredients => params[:ingredients], :cook_time => params[:cook_time]) + redirect "/recipes" + end + + get '/recipes/:id' do + @recipe = Recipe.find(params["id"]) + erb :show + end + + get '/recipes/:id/edit' do + @recipe = Recipe.find(params["id"]) + erb :edit + end + + patch 'recipes/:id' do + @recipe = Recipe.find(params["id"]) + @recipe.name = params[:name] + @recipe.ingredients = params[:ingredients] + @recipe.cook_time = params[:cook_time] + @recipe.save + redirect "/recipes/#{@recipe.id}" + end + + post '/recipes/:id/delete' 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..0fba70f703 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 diff --git a/app/views/edit.erb b/app/views/edit.erb new file mode 100644 index 0000000000..542a53827a --- /dev/null +++ b/app/views/edit.erb @@ -0,0 +1,23 @@ + + + + + +
+ + + + +