Skip to content

Done #1240

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

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

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

gem 'sinatra'
gem 'sqlite3', '~>1.3.6'
gem 'sqlite3'
gem 'tux'
gem 'rake'
gem 'require_all'
gem 'shotgun'
gem 'json'
gem 'pry'
gem 'database_cleaner'

group :test do
gem 'rspec'
gem 'pry-nav'
gem 'capybara'
gem 'rack-test'
gem 'database_cleaner'
end
126 changes: 62 additions & 64 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,64 +1,61 @@
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)
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
activemodel (6.1.3.2)
activesupport (= 6.1.3.2)
activerecord (6.1.3.2)
activemodel (= 6.1.3.2)
activesupport (= 6.1.3.2)
activesupport (6.1.3.2)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
zeitwerk (~> 2.3)
addressable (2.7.0)
public_suffix (>= 2.0.2, < 5.0)
arel (6.0.4)
bond (0.5.1)
builder (3.2.3)
capybara (3.29.0)
capybara (3.35.3)
addressable
mini_mime (>= 0.1.3)
nokogiri (~> 1.8)
rack (>= 1.6.0)
rack-test (>= 0.6.3)
regexp_parser (~> 1.5)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
coderay (1.1.2)
concurrent-ruby (1.1.5)
diff-lcs (1.3)
i18n (0.9.5)
coderay (1.1.3)
concurrent-ruby (1.1.9)
database_cleaner (2.0.1)
database_cleaner-active_record (~> 2.0.0)
database_cleaner-active_record (2.0.1)
activerecord (>= 5.a)
database_cleaner-core (~> 2.0.0)
database_cleaner-core (2.0.1)
diff-lcs (1.4.4)
i18n (1.8.10)
concurrent-ruby (~> 1.0)
json (1.8.6)
json (2.5.1)
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)
mini_portile2 (~> 2.4.0)
mini_mime (1.1.0)
minitest (5.14.4)
mustermann (1.1.1)
ruby2_keywords (~> 0.0.1)
nokogiri (1.11.7-x86_64-darwin)
racc (~> 1.4)
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.6)
racc (1.5.2)
rack (2.2.3)
rack-protection (2.1.0)
rack
rack-test (1.1.0)
rack (>= 1.0, < 3)
rake (13.0.1)
regexp_parser (1.6.0)
rake (13.0.3)
regexp_parser (2.1.1)
require_all (3.0.0)
ripl (0.7.1)
bond (~> 0.5.1)
Expand All @@ -68,49 +65,50 @@ GEM
rack (>= 1.0)
rack-test (>= 0.5)
ripl (>= 0.3.5)
rspec (3.9.0)
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 (3.10.0)
rspec-core (~> 3.10.0)
rspec-expectations (~> 3.10.0)
rspec-mocks (~> 3.10.0)
rspec-core (3.10.1)
rspec-support (~> 3.10.0)
rspec-expectations (3.10.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-mocks (3.9.0)
rspec-support (~> 3.10.0)
rspec-mocks (3.10.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-support (3.9.0)
rspec-support (~> 3.10.0)
rspec-support (3.10.2)
ruby2_keywords (0.0.4)
shotgun (0.9.2)
rack (>= 1.0)
sinatra (2.0.7)
sinatra (2.1.0)
mustermann (~> 1.0)
rack (~> 2.0)
rack-protection (= 2.0.7)
rack (~> 2.2)
rack-protection (= 2.1.0)
tilt (~> 2.0)
sinatra-activerecord (2.0.14)
activerecord (>= 3.2)
sinatra-activerecord (2.0.23)
activerecord (>= 4.1)
sinatra (>= 1.0)
sqlite3 (1.3.13)
thread_safe (0.3.6)
sqlite3 (1.4.2)
tilt (2.0.10)
tux (0.3.0)
ripl (>= 0.3.5)
ripl-multi_line (>= 0.2.4)
ripl-rack (>= 0.2.0)
sinatra (>= 1.2.1)
tzinfo (1.2.5)
thread_safe (~> 0.1)
tzinfo (2.0.4)
concurrent-ruby (~> 1.0)
xpath (3.2.0)
nokogiri (~> 1.8)
zeitwerk (2.4.2)

PLATFORMS
ruby
x86_64-darwin-20

DEPENDENCIES
activerecord (= 4.2.7.1)
activerecord
capybara
database_cleaner!
database_cleaner
json
pry
pry-nav
Expand All @@ -121,8 +119,8 @@ DEPENDENCIES
shotgun
sinatra
sinatra-activerecord
sqlite3 (~> 1.3.6)
sqlite3
tux

BUNDLED WITH
2.0.2
2.2.17
41 changes: 40 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,48 @@
class ApplicationController < Sinatra::Base
# set :views, Proc.new { File.join(root, "../views/") }

configure do
set :public_folder, 'public'
set :views, 'app/views'
end

# code actions here!
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 '/recipe/:id' do
@recipe = Recipe.find_by_id(params[:id])
erb :show
end

get '/recipe/: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

delete '/recipe/: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
13 changes: 13 additions & 0 deletions app/views/edit.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<form method="POST" action="/recipe/<%[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]%>">
<br>
<label for="ingredients">Ingredients:</label>
<input type="text" id="ingredients" name="ingredients" value="<%[email protected]%>">
<br>
<label for="cook_time">Cook Time:</label>
<input type="text" id="cook_time" name="cook_time" value="<%[email protected]_time%>">
<br>
<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>
9 changes: 9 additions & 0 deletions app/views/layout.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!doctype html>
<html>
<head>
<title>Sinatra RESTful Routes</title>
</head>
<body>
<%= yield %>
</body>
</html>
14 changes: 14 additions & 0 deletions app/views/new.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<h1>New Recipe<h1>
<form method="POST" action="/recipes">
<label for="name">Name: </label>
<input type="text" id="name" name="name">
<br>
<label for="ingredients">Ingredients: </label>
<input type="text" id="ingredients" name="ingredients">
<br>
<label for="cook_time">Cook Time: </label>
<input type="text" id="cook_time" name="cook_time">
<br>
<br>
<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 @@
<h1>Recipes<h1>
Name: <%= @recipe.name %>
Ingredients: <%= @recipe.ingredients %>
Cook Time: <%= @recipe.cook_time %>

<form method="POST" action="/recipes/<%= @recipe.id %>">
<input type="hidden" name="_method" value="Delete">
<input type="submit" value="delete">
</form>
6 changes: 3 additions & 3 deletions config.ru
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ require './config/environment'

use Rack::MethodOverride

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

run ApplicationController
Binary file added db/development.sqlite
Binary file not shown.
9 changes: 9 additions & 0 deletions db/migrate/20210606040950_create_recipes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class CreateRecipes < ActiveRecord::Migration[6.1]
def change
create_table :recipes do |t|
t.string :name
t.string :ingredients
t.string :cooke_time
end
end
end
Loading