Skip to content

Done #1236

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 #1236

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.99.0)
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
43 changes: 43 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
8 changes: 8 additions & 0 deletions app/views/edit.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<h1>Edit Recipe</h1>
<form method="POST" action="/recipes/<%= @recipe.id %>">
<input type="hidden" id="hidden" name="_method" value="PATCH">
<p><label for="name">Recipe name: </label><input type="text" id="name" name="name" value="<%= @recipe.name %>"></p>
<p><label for="ingredients">Ingredients (separate by commas): </label><input type="text" id="ingredients" name="ingredients" value="<%= @recipe.ingredients %>"></p>
<p><label for="cook_time">Cook time (in minutes): </label><input type="number" id="cook_time" name="cook_time" value="<%= @recipe.cook_time %>"></p>
<input type="submit">
</form>
11 changes: 11 additions & 0 deletions app/views/index.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<h1>Recipe Database</h1>

<% @recipes.each do |recipe| %>
<h2><a href="/recipes/<%= recipe.id %>"><%= recipe.name %></a></h2>
<p><em>id: <%= recipe.id %></em></p>
<p>
Cook time: <%= recipe.cook_time %> minutes
<br>
Ingredients: <%= recipe.ingredients %>
</p>
<% end %>
7 changes: 7 additions & 0 deletions app/views/new.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<h1>Enter a new recipe:</h1>
<form method="POST" action="/recipes">
<p><label for="name">Recipe name: </label><input type="text" id="name" name="name"></p>
<p><label for="ingredients">Ingredients (separate by commas): </label><input type="text" id="ingredients" name="ingredients"></p>
<p><label for="cook_time">Cook time (in minutes): </label><input type="number" id="cook_time" name="cook_time"></p>
<input type="submit">
</form>
16 changes: 16 additions & 0 deletions app/views/show.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<h1><%= @recipe.name %></h1>
<h2>Cook time: <%= @recipe.cook_time %> minutes</h2>
<h2>Ingredients: <%= @recipe.ingredients %></h2>
<!-- <ul>
<%
ingredients = []
ingredients = @recipe.ingredients.split(",")
ingredients.each do |ingredient|
%>
<li><%= ingredient.strip %></li>
<% end %>
</ul> -->
<form method="POST" action="/recipes/<%= @recipe.id %>">
<input type="hidden" id="hidden" name="_method" value="DELETE">
<input type="submit" name="delete" value="Delete">
</form>
Binary file added db/development.sqlite
Binary file not shown.
9 changes: 9 additions & 0 deletions db/migrate/20210323014452_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.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: 20210323014452) do

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

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