/actionpack/lib/action_controller/metal/redirecting.rb
會什麼可以吃這麼多種設定呢?
# Examples:
# redirect_to :action => "show", :id => 5
# redirect_to post
# redirect_to "http://www.rubyonrails.org"
# redirect_to "/images/screenshot.jpg"
# redirect_to articles_url
# redirect_to :back
# redirect_to proc { edit_post_url(@post) }
def _compute_redirect_to_location(options)
case options
# The scheme name consist of a letter followed by any combination of
# letters, digits, and the plus ("+"), period ("."), or hyphen ("-")
# characters; and is terminated by a colon (":").
# The protocol relative scheme starts with a double slash "//"
when %r{^(\w[\w+.-]*:|//).*}
options
when String
request.protocol + request.host_with_port + options
when :back
raise RedirectBackError unless refer = request.headers["Referer"]
refer
when Proc
_compute_redirect_to_location options.call
else
url_for(options)
end.gsub(/[\0\r\n]/, '')
end
沒有留言:
張貼留言