Skip to content
Open

Done #1228

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
9 changes: 2 additions & 7 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.4)
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 Down
42 changes: 41 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 4 additions & 1 deletion app/models/recipe.rb
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
#Placeholder for a model
#Placeholder for a model
class Recipe < ActiveRecord::Base

end
12 changes: 12 additions & 0 deletions app/views/edit.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<h1>Edit the Recipe here...</h1>
<p>Name: <%= @recipe2.name %></p>
<p>Ingredients: <%= @recipe2.ingredients %></p>
<p>Cook Time: <%= @recipe2.cook_time %></p> minutes

<form action="/recipes/<%= @recipe2.id %>" method="post">
<input id="hidden" type="hidden" name="_method" value="patch">
<input type="text" name="name">
<input type="text" name="ingredients">
<input type="integer" name="cook_time">
<input type="submit" value="submit">
</form>
6 changes: 6 additions & 0 deletions app/views/index.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<h1>List of All Recipes </h1>

<ul> <% @recipes.each do |recipe| %>
<li><a href=<%="/recipes/#{recipe.id}"%>><%= recipe.name %></a></li>
<% end %>
</ul>
8 changes: 8 additions & 0 deletions app/views/new.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<form method="POST" action="/recipes">
<h1>Add your Recipe here..</h1>
<p>Name: <input type="text" name="name"></p>
<p>Ingredients: <input type="text" name="ingredients"></p>
<p>Cook Time: <input type="integer" name="cook_time"></p>

<input type="submit">
</form>
10 changes: 10 additions & 0 deletions app/views/show.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

Here's your <%= @recipe.name %> recipe:<br> <br>

Ingredients: <%= @recipe.ingredients %> <br>
Cook Time: <%= @recipe.cook_time %> minutes

<form action="/recipes/<%= @recipe.id %>" method="post">
<input id="hidden" type="hidden" name="_method" value="delete">
<input type="submit" value="delete">
</form>
Binary file added db/development.sqlite
Binary file not shown.
9 changes: 9 additions & 0 deletions db/migrate/20200425051557_recipes.rb
Original file line number Diff line number Diff line change
@@ -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
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: 20200425051557) do

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

end
5 changes: 5 additions & 0 deletions db/seeds.rb
Original file line number Diff line number Diff line change
@@ -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)
Binary file modified db/test.sqlite
Binary file not shown.