forked from saterus/hello_sinatra
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.rb
More file actions
48 lines (36 loc) · 788 Bytes
/
server.rb
File metadata and controls
48 lines (36 loc) · 788 Bytes
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
require 'sinatra'
get '/' do
# default route
# get = show
# return strings
"Hello Sinatra!"
end
post "/add" do
# post = create something
# .. complicated stuff happens
"...Created!"
end
get "/http_methods" do
erb :http_methods
end
# just serves files (images, css, js, etc.)
set :public_folder, File.dirname(__FILE__) + '/public' # default
# multiple routes
get "/hello/cwdg" do
"<h1>Hello CWDG</h1>"
end
get "/hello" do
"<h1>Hello Student</h1>"
end
# parameters
get "/hi/:name" do
$name = params[:name]
"<h1>Hello #{$name.capitalize}</h1>"
end
# set view directory
set :views, settings.root + '/views' # default
get "/templating" do
@name = $name || 'Student'
@footer_class = rand > 0.5 ? "blue" : "green"
erb :templating, layout: :layout
end