-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
62 lines (50 loc) · 1.13 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
require "sinatra"
require "sinatra/reloader" if development?
require "pry-byebug"
require "better_errors"
require_relative 'cookbook'
require_relative 'scrapeservice'
csv_file = File.join(__dir__, 'recipes.csv')
cookbook = Cookbook.new(csv_file)
configure :development do
use BetterErrors::Middleware
BetterErrors.application_root = File.expand_path('..', __FILE__)
end
get '/' do
@recipearray = cookbook.all
erb :index
end
get '/addcustom' do
erb :addcustom
end
post '/addcustom' do
@new_recipe = {name: params[:name],
description: params[:description],
duration: params[:duration]}
cookbook.add_recipe(Recipe.new(@new_recipe))
redirect '/'
end
post '/remove' do
params = JSON.parse(request.body.read)
cookbook.remove_recipe(params["index"].to_i)
redirect '/'
end
get '/lookup' do
erb :lookup
end
post "/lookup" do
p params
p @holder = ScrapeService.new(params[:key]).scrapedobject
erb :lookup
end
post '/tester' do
# p params
@test = params
p @test
@test["p"].each do |hash|
if hash['on']
cookbook.add_recipe(Recipe.new(hash))
end
end
erb :tester
end