forked from code61/sinatra_c3s2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.rb
41 lines (32 loc) · 854 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
require 'sinatra'
get '/' do
output = "<form method='post' action='/'>"
output += "<input type='text' name='user_name' placeholder='name'>"
output += "<input type='text' name='user_age' placeholder='age'>"
output += "<button type='submit'>Submit</button>"
output += "</form>"
output
end
post '/' do
name = params[:user_name]
age = params[:user_age].to_i # to_i converts the string "5" to the integer 5
if age >= 18
output = "Hello #{name.capitalize}. Here's your drink."
else
output = "This bar isn't the place for you, #{name.capitalize}. You're too young."
end
output += " <br><br><a href='/'>again</a>"
output
end
# get '/' do
# erb :form
# end
# post '/' do
# @name = params[:user_name]
# @age = params[:user_age].to_i
# if @age >= 18
# erb :drink
# else
# erb :no_drink
# end
# end