document redirect, fixes #162

This commit is contained in:
Konstantin Haase 2011-02-18 11:06:00 +01:00
parent 9a22d7c81c
commit 2eae9406ff
1 changed files with 31 additions and 1 deletions

View File

@ -762,7 +762,7 @@ A route can punt processing to the next matching route using <tt>pass</tt>:
The route block is immediately exited and control continues with the next The route block is immediately exited and control continues with the next
matching route. If no matching route is found, a 404 is returned. matching route. If no matching route is found, a 404 is returned.
=== Setting body and status === Setting Body and Status Code
It is possible and recommended to set the status code and response body with the It is possible and recommended to set the status code and response body with the
return value of the route block. However, in some scenarios you might want to return value of the route block. However, in some scenarios you might want to
@ -789,6 +789,36 @@ Similar to the body, you can also set the status code:
halt "I'm a tea pot!" halt "I'm a tea pot!"
end end
=== Browser Redirect
You can trigger a browser redirect with the `redirect` helper method:
get '/foo' do
redirect '/bar'
end
Any additional parameters are handled like arguments passed to `halt`:
redirect '/bar', 303
redirect '/bar', 'wrong place, buddy'
To pass arguments with a redirect, either add them to the query:
redirect '/bar?sum=42'
Or use a session:
enable :session
get '/foo' do
session[:secret] = 'foo'
redirect '/bar'
end
get '/bar' do
session[:secret]
end
=== Accessing the Request Object === Accessing the Request Object
The incoming request object can be accessed from request level (filter, routes, error handlers) through the `request` method: The incoming request object can be accessed from request level (filter, routes, error handlers) through the `request` method: