M routes.rb => routes.rb +11 -1
@@ 2,5 2,15 @@
ROUTES = [
{ path: '/' },
- { path: '/leanweb/readme.html' }
+ { path: '/leanweb/readme.html' },
+ {
+ path: %r{^/hello/(\w+)$},
+ action: ->(who) { greet(who) },
+ static: false
+ },
+ {
+ path: %r{^/hello/(\w+).html$},
+ action: { MainController: :hello_get },
+ static: [ ['World'], ['LibrePlanet'] ]
+ }
].freeze
M src/controllers/main_controller.rb => src/controllers/main_controller.rb +9 -0
@@ 7,4 7,13 @@ class MainController < LeanWeb::Controller
def index_get
render_response 'index.haml'
end
+
+ def greet(who)
+ @response.write("Hello, #{who}!")
+ @response.finish
+ end
+
+ def hello_get(who)
+ render_response('hello.erb', { who: who }, 'text/html')
+ end
end
A src/views/hello.erb => src/views/hello.erb +1 -0
@@ 0,0 1,1 @@
+<h1>Hello, <%= who %></h1>