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..eeb5750947 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -3,6 +3,46 @@ class ApplicationController < Sinatra::Base set :public_folder, 'public' set :views, 'app/views' end + + get '/recipes' do + @recipes = Recipe.all + erb :index + end + + get '/recipes/new' do + erb :new + end + + post '/recipes' do + @recipe = Recipe.create(:name => params[:name], :ingredients => params[:ingredients], :cook_time => params[:cook_time]) + 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 + @recipe = Recipe.find_by_id(params[:id]) + erb :edit + end + + patch '/recipes/:id' do #edit action + @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 + + delete '/recipes/:id' do #delete action + @recipe = Recipe.find_by_id(params[:id]) + @recipe.delete + redirect to '/recipes' + end + # code actions here! diff --git a/app/models/recipe.rb b/app/models/recipe.rb index 2677f6e06b..2d2e224f43 100644 --- a/app/models/recipe.rb +++ b/app/models/recipe.rb @@ -1 +1,5 @@ -#Placeholder for a model \ No newline at end of file +#Placeholder for a model + +class Recipe < ActiveRecord::Base + #has_secure_password +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..953df6fcc5 --- /dev/null +++ b/app/views/edit.erb @@ -0,0 +1,14 @@ +
Ingredients: <%=@recipe.ingredients%>
+Cook Time: <%=@recipe.cook_time%>
+ + \ No newline at end of file diff --git a/app/views/index.erb b/app/views/index.erb index e69de29bb2..85dc4dec18 100644 --- a/app/views/index.erb +++ b/app/views/index.erb @@ -0,0 +1,8 @@ +Name: <%=item.name%>
+Ingredients: <%=item.ingredients%>
+Cook Time: <%=item.cook_time%>
+Recipe Page +<%end%> \ No newline at end of file diff --git a/app/views/new.erb b/app/views/new.erb new file mode 100644 index 0000000000..9902aa8e59 --- /dev/null +++ b/app/views/new.erb @@ -0,0 +1,8 @@ +Ingredients: <%=@recipe.ingredients%>
+Cook Time: <%=@recipe.cook_time%>
+ + \ No newline at end of file diff --git a/config/environment.rb b/config/environment.rb index ab976d3e66..01603b87e1 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,8 +1,12 @@ +#use Rack::MethodOverride + ENV['SINATRA_ENV'] ||= "development" require 'bundler/setup' Bundler.require(:default, ENV['SINATRA_ENV']) +use Rack::MethodOverride + ActiveRecord::Base.establish_connection( :adapter => "sqlite3", :database => "db/#{ENV['SINATRA_ENV']}.sqlite" diff --git a/db/development.sqlite b/db/development.sqlite new file mode 100644 index 0000000000..c5a283de23 Binary files /dev/null and b/db/development.sqlite differ diff --git a/db/migrate/20200107180404_create_recipes.rb b/db/migrate/20200107180404_create_recipes.rb new file mode 100644 index 0000000000..26f6bff678 --- /dev/null +++ b/db/migrate/20200107180404_create_recipes.rb @@ -0,0 +1,13 @@ +class CreateRecipes < ActiveRecord::Migration + def up + create_table :recipes do |t| + t.string :name + t.string :ingredients + t.string :cook_time + end +end + + def down + drop_table :recipes + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000000..ab269cccff --- /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: 20200107180404) 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 e69de29bb2..393e2570bb 100644 Binary files a/db/test.sqlite and b/db/test.sqlite differ