Skip to content

Done #1226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Done #1226

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -35,6 +29,7 @@ GEM
xpath (~> 3.2)
coderay (1.1.2)
concurrent-ruby (1.1.5)
database_cleaner (1.8.3)
diff-lcs (1.3)
i18n (0.9.5)
concurrent-ruby (~> 1.0)
Expand Down Expand Up @@ -110,7 +105,7 @@ PLATFORMS
DEPENDENCIES
activerecord (= 4.2.7.1)
capybara
database_cleaner!
database_cleaner
json
pry
pry-nav
Expand All @@ -125,4 +120,4 @@ DEPENDENCIES
tux

BUNDLED WITH
2.0.2
2.1.4
43 changes: 42 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,47 @@ class ApplicationController < Sinatra::Base
set :views, 'app/views'
end

# code actions here!
get '/' do
redirect to "/recipes"
end

get '/recipes' do
erb :index
end

get '/recipes/new' do
erb :new
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
@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
@recipe = Recipe.create(:name => params[:name], :ingredients => params[:ingredients], :cook_time => params[:cook_time])
redirect to "/recipes/#{@recipe.id}"
end

delete '/recipes/:id' do
@recipe = Recipe.find_by_id(params[:id])
@recipe.delete
redirect to '/recipes'
end

end
3 changes: 2 additions & 1 deletion app/models/recipe.rb
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#Placeholder for a model
class Recipe < ActiveRecord::Base
end
22 changes: 22 additions & 0 deletions app/views/edit.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html>
<head>
<title>Edit Recipe Form</title>
</head>
<body>
<h1>Here is The Selected Recipe</h1>
<h2>Recipe No. <%= @recipe.id %></h2>
<p>Recipe Name: <%= @recipe.name %></p>
<p>Ingredients: <%= @recipe.ingredients %></p>
<p>Cook Time: <%= @recipe.cook_time %></p>

<h1>Enter Your Updated Recipe Info Here: for Recipe No. <%= @recipe.id %></h1>
<form method="POST" action="/recipes/<%= @recipe.id %>">
<input id="hidden" type="hidden" name="_method" value="patch">
<p>New Recipe Name: <input type="text" name="name"></p>
<p>New Recipe Ingredients: <input type="text" name="ingredients"></p>
<p>New Recipe Cook Time: <input type="text" name="cook_time"></p>
<input type="submit" value="Submit yo recipe">
</form>
</body>
</html>
14 changes: 14 additions & 0 deletions app/views/index.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>Here are Gramdma's Recipes</h1>
<% @recipes = Recipe.all %>
<% @recipes.each do |x| %>
<p><a href="/recipes/<%=x.id%>"><%= x.name %></a></p>
<% end %>

<p>To add a new recipe, click <a href="/recipes/new">here</a></p>
</body>
</html>
16 changes: 16 additions & 0 deletions app/views/new.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<title>New Recipe Form</title>
</head>
<body>
<h1>New Recipe Form</h1>
<h2>Enter Your New Recipe Info Here:</h2>
<form method="POST" action="/recipes">
<p>Recipe Name: <input type="text" name="name"></p>
<p>Recipe Ingredients: <input type="text" name="ingredients"></p>
<p>Recipe Cook Time: <input type="text" name="cook_time"></p>
<input type="submit" value="Submit yo recipe">
</form>
</body>
</html>
19 changes: 19 additions & 0 deletions app/views/show.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>
<head>
<title>Recipe Display</title>
</head>
<body>
<h1>Here is The Selected Recipe</h1>
<h2>Recipe No. <%= @recipe.id %></h2>
<p>Recipe Name: <%= @recipe.name %></p>
<p>Ingredients: <%= @recipe.ingredients %></p>
<p>Cook Time: <%= @recipe.cook_time %></p>

<form method="POST" action="/recipes/<%= @recipe.id %>">
<input id="hidden" type="hidden" name="_method" value="delete">
<input type="submit" value="delete">
</form>
</body>

</html>
Binary file added db/development.sqlite
Binary file not shown.
9 changes: 9 additions & 0 deletions db/migrate/20200327172825_create_recipes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class CreateRecipes < ActiveRecord::Migration
def change
create_table :recipes do |t|
t.string :name
t.string :ingredients
t.string :cook_time
end
end
end
22 changes: 22 additions & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
@@ -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: 20200327172825) do

create_table "recipes", force: :cascade do |t|
t.string "name"
t.string "ingredients"
t.string "cook_time"
end

end
Binary file modified db/test.sqlite
Binary file not shown.