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..e20694b096 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -4,6 +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 + + post '/recipes' do + @recipe = Recipe.create(params) + redirect to "/recipes/#{@recipe.id}" + end + + get '/recipes/:id' do + @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/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..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 e69de29bb2..93f9706287 100644 --- a/app/views/index.erb +++ b/app/views/index.erb @@ -0,0 +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 new file mode 100644 index 0000000000..88922c0db3 --- /dev/null +++ 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 new file mode 100644 index 0000000000..f7d19e7cc5 Binary files /dev/null and b/db/development.sqlite differ 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/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 e69de29bb2..626bdbeb50 100644 Binary files a/db/test.sqlite and b/db/test.sqlite differ