2015年3月26日 星期四

Rails 3.2.20 redirecting class 內的 _compute_redirect_to_location

Rails 3.2.20 中的 redirecting.rb 
/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

【下列文章您可能也有興趣】

沒有留言: