-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
40 lines (34 loc) · 878 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
require 'sinatra'
require 'sinatra/reloader' if development?
require 'pry-byebug'
require 'better_errors'
require_relative 'cookbook'
require_relative 'recipe'
configure :development do
use BetterErrors::Middleware
BetterErrors.application_root = File.expand_path(__dir__, __FILE__)
end
csv_file = File.join(__dir__, 'recipes.csv')
cookbook = Cookbook.new(csv_file)
get '/' do
@recipes = cookbook.all
erb :index
end
get '/new' do
erb :new
end
post '/' do
@title = params['title']
@description = params['description']
@prep_time = params['prep_time']
@difficulty = params['difficulty']
recipe = Recipe.new(@title, @description, @prep_time, @difficulty)
cookbook.add_recipe(recipe)
@recipes = cookbook.all
redirect to('/')
end
get '/:index' do
delete_index = params['index'].to_i
cookbook.remove_recipe(delete_index)
redirect to('/')
end