-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.rb
44 lines (38 loc) · 982 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
require 'sinatra'
require 'yaml/store'
CHOICES = {
'happy' => 'Happy',
'divaka' => 'Дивака',
'krivoto' => 'Кривото',
'ugo' => 'Уго',
'mr-pizza' => 'Мистър Пица',
'sun-moon' => 'Слънце луна',
'soul-kitchen' => 'Soul Kitchen',
}
votes = {}
get '/' do
@title = 'Добре дошли в машината за гласуване!'
erb :index
end
post '/cast' do
@title = 'Благодарим за вашия глас!'
@vote = params['vote']
@store = YAML::Store.new 'votes.yml'
@store.transaction do
if @store['votes'] == nil
@store['votes'] = {}
end
if @store['votes'][@vote]
@store['votes'][@vote] = @store['votes'][@vote] + 1
else
@store['votes'][@vote] = 1
end
end
erb :cast
end
get '/results' do
@title = 'Results so far:'
@store = YAML::Store.new 'votes.yml'
@votes = @store.transaction { @store['votes'] }
erb :results
end