Skip to content

Commit e0a513c

Browse files
committed
again
1 parent 78293fe commit e0a513c

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/tinyrails.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ def call(_env)
1717
return [302, { 'location' => '/tweets/a_tweet' }, ['<html><body>Redirecting...</body></html>']]
1818
end
1919

20-
klass, act = get_controller_and_action(_env)
20+
if env['REQUEST_METHOD'] == "POST"
21+
klass, id, act = post_controller_and_action(_env)
22+
env['route.id'] = id
23+
else
24+
klass, act = get_controller_and_action(_env)
25+
end
26+
2127
controller = klass.new(_env)
2228
text = controller.send(act)
2329
[200, { 'content-type' => 'text/html' }, [text]]

lib/tinyrails/routing.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,14 @@ def get_controller_and_action(env)
1010

1111
[Object.const_get(controller), action]
1212
end
13+
14+
def post_controller_and_action(env)
15+
_, controller, id, action = env['PATH_INFO'].split('/', 4)
16+
17+
controller = controller.capitalize
18+
controller += 'Controller'
19+
20+
[Object.const_get(controller), id, action]
21+
end
1322
end
1423
end

0 commit comments

Comments
 (0)