diff --git a/Gemfile.lock b/Gemfile.lock index 7d1a42a53f..95b266eebb 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.99.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..9d7940cda7 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -5,5 +5,48 @@ class ApplicationController < Sinatra::Base end # code actions here! + get '/recipes' do + @recipes = Recipe.all + + erb :index + end + + get '/recipes/new' do + erb :'new' + end + + get '/recipes/:id' do + @recipe = Recipe.find(params[:id]) + + erb :show + 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 + + delete '/recipes/:id' do + Recipe.destroy(params[:id]) + + redirect '/recipes' + end + + get '/recipes/:id/edit' do + @recipe = Recipe.find(params[:id]) + + erb :'edit' + end + + post '/recipes' do + recipe = Recipe.new(name: params[:name], ingredients: params[:ingredients], cook_time: params[:cook_time]) + recipe.save + redirect "/recipes/#{recipe.id}" + 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..b466270e02 --- /dev/null +++ b/app/views/edit.erb @@ -0,0 +1,8 @@ +

Edit Recipe

+
+ +

+

+

+ +
diff --git a/app/views/index.erb b/app/views/index.erb index e69de29bb2..00b3423531 100644 --- a/app/views/index.erb +++ b/app/views/index.erb @@ -0,0 +1,11 @@ +

Recipe Database

+ +<% @recipes.each do |recipe| %> +

<%= recipe.name %>

+

id: <%= recipe.id %>

+

+ Cook time: <%= recipe.cook_time %> minutes +
+ Ingredients: <%= recipe.ingredients %> +

+<% end %> diff --git a/app/views/new.erb b/app/views/new.erb new file mode 100644 index 0000000000..b10bf97a8f --- /dev/null +++ b/app/views/new.erb @@ -0,0 +1,7 @@ +

Enter a new recipe:

+
+

+

+

+ +
diff --git a/app/views/show.erb b/app/views/show.erb new file mode 100644 index 0000000000..14d45a9931 --- /dev/null +++ b/app/views/show.erb @@ -0,0 +1,16 @@ +

<%= @recipe.name %>

+

Cook time: <%= @recipe.cook_time %> minutes

+

Ingredients: <%= @recipe.ingredients %>

+ +
+ + +
diff --git a/db/development.sqlite b/db/development.sqlite new file mode 100644 index 0000000000..5cac9b57ae Binary files /dev/null and b/db/development.sqlite differ diff --git a/db/migrate/20210323014452_create_recipes.rb b/db/migrate/20210323014452_create_recipes.rb new file mode 100644 index 0000000000..15b5d7a1d2 --- /dev/null +++ b/db/migrate/20210323014452_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.integer :cook_time + end + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000000..635a888f36 --- /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: 20210323014452) 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 e69de29bb2..d9eb74d336 100644 Binary files a/db/test.sqlite and b/db/test.sqlite differ