-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.rb
69 lines (58 loc) · 1.51 KB
/
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
require 'sinatra'
require 'sinatra/reloader' if development?
require 'pry-byebug'
require 'better_errors'
require './lib/cookbook'
require './lib/recipe'
require './lib/service'
set :bind, '0.0.0.0'
configure :development do
use BetterErrors::Middleware
BetterErrors.application_root = File.expand_path('..', __FILE__)
end
get '/' do
csv_file = File.join(__dir__, './lib/recipes.csv')
cookbook = Cookbook.new(csv_file)
@recipes = cookbook.all
erb :index
end
get '/new' do
erb :new
end
post '/recipes' do
@recipe = Recipe.new({ name: params[:name], description: params[:description], rating: params[:rating], prep_time: params[:prep_time], done: false })
csv_file = File.join(__dir__, './lib/recipes.csv')
cookbook = Cookbook.new(csv_file)
cookbook.add_recipe(@recipe)
redirect to '/'
end
get '/destroy/:index' do
csv_file = File.join(__dir__, './lib/recipes.csv')
cookbook = Cookbook.new(csv_file)
cookbook.remove_recipe(params[:index].to_i)
redirect to '/'
end
get '/search' do
erb :search
end
post '/import' do
# @results = Service.new(params[:ingredient]).scrape_recipes
# binding.pry
redirect to "/results/:#{params[:ingredient]}"
end
get '/results/:ingredient' do
@recipes = Service.new(params[:ingredient]).scrape_recipes
erb :results
end
get '/test' do
# '<h1>Hello <em>world</em>!</h1>'
@usernames = %w[ssaunier Papillard]
erb :test
end
get '/about' do
erb :about
end
get '/team/:username' do
puts params[:username]
"The username is #{params[:username]}"
end