-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.rb
50 lines (41 loc) · 964 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
44
45
46
47
48
49
50
require 'rubygems'
require 'sinatra'
require 'haml'
require 'config'
require 'dm-core'
require 'dm-migrations'
require 'pp'
before do
params.map { |key, val| params[key] = val.split(' ').map { |w| w.capitalize }.join(' ') }
end
get '/' do
"<a href=/beer>beer</a> or <a href=/drink>cocktail</a>"
end
get '/beer' do
all = Beer.all
@beer = all[rand(all.size)]
haml :beer
end
get '/drink' do
all = Drink.all
@drink = all[rand(all.size)]
haml :drink
end
post '/newdrink' do
unit = Unit.first_or_create(:name => params[:unit])
ingredient = Ingredient.first_or_create(:name => params[:ingredient], :amount => params[:amount].to_f, :unit => unit)
drink = Drink.first_or_create(:name => params[:drink])
drink.ingredients << ingredient
drink.save
redirect '/drink'
end
post '/newbeer' do
Beer.first_or_create(:name => params[:beer])
redirect '/beer'
end
get '/adddrink' do
haml :adddrink
end
get '/addbeer' do
haml :addbeer
end