Skip to content
Open

Done #1227

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
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source 'http://rubygems.org'

gem 'activerecord', '4.2.7.1', :require => 'active_record'
gem 'activerecord', '~> 5.2', '>= 5.2.2.1'
gem 'sinatra-activerecord', :require => 'sinatra/activerecord'

gem 'sinatra'
Expand Down
74 changes: 34 additions & 40 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,31 +1,22 @@
GIT
remote: https://github.com/bmabey/database_cleaner.git
revision: 85767fa7011355049aa526ffa1f99c6972b98fbf
specs:
database_cleaner (1.8.0)

GEM
remote: http://rubygems.org/
specs:
activemodel (4.2.7.1)
activesupport (= 4.2.7.1)
builder (~> 3.1)
activerecord (4.2.7.1)
activemodel (= 4.2.7.1)
activesupport (= 4.2.7.1)
arel (~> 6.0)
activesupport (4.2.7.1)
i18n (~> 0.7)
json (~> 1.7, >= 1.7.7)
activemodel (5.2.4.1)
activesupport (= 5.2.4.1)
activerecord (5.2.4.1)
activemodel (= 5.2.4.1)
activesupport (= 5.2.4.1)
arel (>= 9.0)
activesupport (5.2.4.1)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
addressable (2.7.0)
public_suffix (>= 2.0.2, < 5.0)
arel (6.0.4)
arel (9.0.0)
bond (0.5.1)
builder (3.2.3)
capybara (3.29.0)
capybara (3.31.0)
addressable
mini_mime (>= 0.1.3)
nokogiri (~> 1.8)
Expand All @@ -34,31 +25,33 @@ GEM
regexp_parser (~> 1.5)
xpath (~> 3.2)
coderay (1.1.2)
concurrent-ruby (1.1.5)
concurrent-ruby (1.1.6)
database_cleaner (1.8.3)
diff-lcs (1.3)
i18n (0.9.5)
i18n (1.8.2)
concurrent-ruby (~> 1.0)
json (1.8.6)
json (2.3.0)
method_source (0.9.2)
mini_mime (1.0.2)
mini_portile2 (2.4.0)
minitest (5.13.0)
mustermann (1.0.3)
nokogiri (1.10.5)
minitest (5.14.0)
mustermann (1.1.1)
ruby2_keywords (~> 0.0.1)
nokogiri (1.10.9)
mini_portile2 (~> 2.4.0)
pry (0.12.2)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
pry-nav (0.3.0)
pry (>= 0.9.10, < 0.13.0)
public_suffix (4.0.1)
rack (2.0.7)
rack-protection (2.0.7)
public_suffix (4.0.3)
rack (2.2.2)
rack-protection (2.0.8.1)
rack
rack-test (1.1.0)
rack (>= 1.0, < 3)
rake (13.0.1)
regexp_parser (1.6.0)
regexp_parser (1.7.0)
require_all (3.0.0)
ripl (0.7.1)
bond (~> 0.5.1)
Expand All @@ -72,21 +65,22 @@ GEM
rspec-core (~> 3.9.0)
rspec-expectations (~> 3.9.0)
rspec-mocks (~> 3.9.0)
rspec-core (3.9.0)
rspec-support (~> 3.9.0)
rspec-expectations (3.9.0)
rspec-core (3.9.1)
rspec-support (~> 3.9.1)
rspec-expectations (3.9.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-mocks (3.9.0)
rspec-mocks (3.9.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-support (3.9.0)
rspec-support (3.9.2)
ruby2_keywords (0.0.2)
shotgun (0.9.2)
rack (>= 1.0)
sinatra (2.0.7)
sinatra (2.0.8.1)
mustermann (~> 1.0)
rack (~> 2.0)
rack-protection (= 2.0.7)
rack-protection (= 2.0.8.1)
tilt (~> 2.0)
sinatra-activerecord (2.0.14)
activerecord (>= 3.2)
Expand All @@ -99,7 +93,7 @@ GEM
ripl-multi_line (>= 0.2.4)
ripl-rack (>= 0.2.0)
sinatra (>= 1.2.1)
tzinfo (1.2.5)
tzinfo (1.2.6)
thread_safe (~> 0.1)
xpath (3.2.0)
nokogiri (~> 1.8)
Expand All @@ -108,9 +102,9 @@ PLATFORMS
ruby

DEPENDENCIES
activerecord (= 4.2.7.1)
activerecord (~> 5.2, >= 5.2.2.1)
capybara
database_cleaner!
database_cleaner
json
pry
pry-nav
Expand Down
45 changes: 45 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,54 @@
require './config/environment'

class ApplicationController < Sinatra::Base
configure do
set :public_folder, 'public'
set :views, 'app/views'
end

# code actions here!
get '/recipes' do
@recipes = Recipe.all
erb :index
end

get '/recipes/new' do
erb :new
end

# get '/recipes/search' do
# @recipe = Recipe.find_by(:name => params[:name])
# erb :show
# 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

post '/recipes' do
@recipe = Recipe.create(params)
redirect to "/recipes/#{@recipe.id}"
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

delete '/recipes/:id' do
@recipe = Recipe.find_by(:id => 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
14 changes: 14 additions & 0 deletions app/views/edit.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<form method="POST" action="/recipes/<%[email protected]%>">
<input id="hidden" type="hidden" name="_method" value="patch" >

<label for="name">Name</label>
<input type="text" id="name" name="name" value="<%[email protected]%>" >

<label for="ingredients">Ingredients</label>
<input type="text" id="ingredients" name="ingredients" value="<%[email protected]%>" >

<label for="cook_time">Cook Time</label>
<input type="text" id="cook_time" name="cook_time" value="<%[email protected]_time%>" >

<input type="submit" value="submit" >
</form>
9 changes: 9 additions & 0 deletions app/views/index.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<ul>
<% @recipes.each do |recipe|%>
<li>
<a href="/recipes/<%= recipe.id %>">Name: <%= recipe.name %></a>
Ingredients: <%= recipe.ingredients %>
Cook time <%= recipe.cook_time %>
</li>
<% end %>
</ul>
13 changes: 13 additions & 0 deletions app/views/new.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<form method="POST" action="/recipes">

<label for="name">Name</label>
<input type="text" id="name" name="name" />

<label for="ingredients">Ingredients</label>
<input type="text" id="ingredients" name="ingredients" />

<label for="cook_time">Cook Time</label>
<input type="text" id="cook_time" name="cook_time" />

<input type="submit" value="submit" />
</form>
8 changes: 8 additions & 0 deletions app/views/show.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<h1><%= @recipe.name %></h1>
<p><%= @recipe.ingredients %></p>
<p><%= @recipe.cook_time %></p>

<form method="POST" action="/recipes/<%[email protected]%>">
<input id= "hidden" type="hidden" name="_method" value="DELETE">
<button type="submit" value="delete">Delete Recipe</button>
</form>
2 changes: 1 addition & 1 deletion config.ru
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ require './config/environment'

use Rack::MethodOverride

if ActiveRecord::Migrator.needs_migration?
if ActiveRecord::Base.connection.migration_context.needs_migration?
raise 'Migrations are pending. Run `rake db:migrate` to resolve the issue.'
end

Expand Down
Binary file added db/development.sqlite
Binary file not shown.
9 changes: 9 additions & 0 deletions db/migrate/01_create_recipes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class CreateRecipes < ActiveRecord::Migration[5.2]
def change
create_table "recipes" do |t|
t.string :name
t.string :ingredients
t.string :cook_time
end
end
end
21 changes: 21 additions & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 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: 1) 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.
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
require 'capybara/rspec'
require 'capybara/dsl'

if defined?(ActiveRecord::Migrator) && ActiveRecord::Migrator.needs_migration?
if defined?(ActiveRecord::Migrator) && ActiveRecord::Base.connection.migration_context.needs_migration?
raise 'Migrations are pending run `rake db:migrate SINATRA_ENV=test` to resolve the issue.'
end

Expand Down