Skip to content

Done #1219

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 5 commits into
base: master
Choose a base branch
from
Open

Done #1219

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.7.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
40 changes: 40 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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!

Expand Down
6 changes: 5 additions & 1 deletion app/models/recipe.rb
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
#Placeholder for a model
#Placeholder for a model

class Recipe < ActiveRecord::Base
#has_secure_password
end
14 changes: 14 additions & 0 deletions app/views/edit.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<h3>Edit a Recipe</h3>

<h3><%[email protected]%></h3>

<p>Ingredients: <%[email protected]%></p>
<p>Cook Time: <%[email protected]_time%></p>

<form action="/recipes/<%= @recipe.id %>" method="post">
<input id="hidden" type="hidden" name="_method" value="patch">
<input type="text" name="name" placeholder="Name:">
<input type="text" name="ingredients" placeholder="Ingredients:">
<input type="text" name="cook_time" placeholder="Cook Time:">
<input type="submit" value="submit">
</form>
8 changes: 8 additions & 0 deletions app/views/index.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<h3>Your Recipes</h3>

<%@recipes.each do |item|%>
<p>Name: <%=item.name%></p>
<p>Ingredients: <%=item.ingredients%></p>
<p>Cook Time: <%=item.cook_time%></p>
<a href="/recipes/<%=item.id%>">Recipe Page</a>
<%end%>
8 changes: 8 additions & 0 deletions app/views/new.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<h3>New Recipe Form</h3>

<form action="/recipes" method="POST">
<input type="text" name="name" placeholder="Name:">
<input type="text" name="ingredients" placeholder="Ingredients:">
<input type="text" name="cook_time" placeholder="Cook Time:">
<input type="submit" value="Submit">
</form>
9 changes: 9 additions & 0 deletions app/views/show.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<h3><%[email protected]%></h3>

<p>Ingredients: <%[email protected]%></p>
<p>Cook Time: <%[email protected]_time%></p>

<form method = "post" action="/recipes/<%[email protected] %>">
<input id ="hidden" type="hidden" name="_method" value="DELETE">
<input type="submit" value="delete">
</form>
4 changes: 4 additions & 0 deletions config/environment.rb
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
Binary file added db/development.sqlite
Binary file not shown.
13 changes: 13 additions & 0 deletions db/migrate/20200107180404_create_recipes.rb
Original file line number Diff line number Diff line change
@@ -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
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: 20200107180404) 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.