generated from Rails-Girls-Warsaw/codespace-start
-
Notifications
You must be signed in to change notification settings - Fork 0
/
picka.rb
43 lines (34 loc) · 777 Bytes
/
picka.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
require 'sinatra'
require 'yaml/store'
Choices = {
"pizza" => "Pizza",
"barszcz-ukrainski" => "Barszcz ukrainski",
"pierogi" => "Pierogi",
"schaboszczak" => "Kotlecik schabowy"
}
get '/' do
@title = "Co tam sobie dzisiaj zjemy?"
erb :index
end
post '/cast' do
@title = "Tutaj będzie co wybrałeś"
@choice = Choices[params["vote"]]
@vote = params["vote"]
@store = YAML::Store.new 'votes.yml'
@store.transaction do
@store['votes'] ||= {}
@store['votes'][@vote] ||= 0
@store['votes'][@vote] += 1
end
erb :cast
end
get '/results' do
@title = "Nasze wyniczki! Mniam mniam"
@store = YAML::Store.new 'votes.yml'
@votes = @store.transaction do
@store['votes'] ||= {}
@store['votes']
end
puts @votes
erb :results
end