-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.rb
43 lines (35 loc) · 797 Bytes
/
app.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
require 'sinatra'
require 'sinatra/reloader' if development?
require 'pry-byebug'
require 'better_errors'
require_relative 'lib/cookbook.rb'
require_relative 'lib/recipe.rb'
configure :development do
use BetterErrors::Middleware
BetterErrors.application_root = File.expand_path('..', __FILE__)
end
csv_file = File.join(__dir__, 'lib/recipes.csv')
cookbook = Cookbook.new(csv_file)
get '/' do
@recipes = cookbook.recipes
# binding.pry
erb :index
end
# [...]
get '/about' do
erb :about
end
get '/new' do
erb :new
end
post '/recipes' do
# p params[:name]
# p params[:description]
cookbook.add_recipe(Recipe.new(params[:name], params[:description]))
redirect "/"
end
post '/delete' do
# binding.pry
cookbook.remove_recipe(params.first[0].to_i)
redirect "/"
end