2008年9月7日 星期日

redirect_to

http://api.rubyonrails.org/classes/ActionController/Base.html#M000852
http://en.wikipedia.org/wiki/List_of_HTTP_status_codes

  redirect_to post
redirect_to :action => "show", :id => 5
redirect_to "http://www.rubyonrails.org"
redirect_to "/images/screenshot.jpg"
redirect_to articles_url
redirect_to :back

The redirection happens as a "302 Moved" header unless otherwise specified.

Examples:

  redirect_to post_url(@post), :status=>:found
redirect_to :action=>'atom', :status=>:moved_permanently
redirect_to post_url(@post), :status=>301
redirect_to :action=>'atom', :status=>302

:back - Back to the page that issued the request. Useful for forms that are triggered from multiple places. Short-hand for redirect_to(request.env["HTTP_REFERER"])



301 Moved Permanently
This and all future requests should be directed to the given URI.

302 Found
This is the most popular redirect code, but also an example of industrial practice contradicting the standard. HTTP/1.0 specification (RFC 1945) required the client to perform a temporary redirect (the original describing phrase was "Moved Temporarily"), but popular browsers implemented it as a 303 See Other. Therefore, HTTP/1.1 added status codes 303 and 307 to disambiguate between the two behaviours. However, the majority of Web applications and frameworks still use the 302 status code as if it were the 303.
303 See Other (since HTTP/1.1)
The response to the request can be found under another URI using a GET method.
307 Temporary Redirect (since HTTP/1.1)
In this occasion, the request should be repeated with another URI, but future requests can still use the original URI. In contrast to 303, the request method should not be changed when reissuing the original request. For instance, a POST request must be repeated using another POST request.

沒有留言: