From 0367317dd62ecd177d57d469a4d57974b75e425b Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 22 May 2005 07:43:05 +0000 Subject: Deprecated redirect_to_path and redirect_to_url in favor of letting redirect_to do the right thing when passed either a path or url. Introduced r as a unified method for render (still under construction) git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1349 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_controller/request.rb | 37 ++++++++++++++--------------- 1 file changed, 18 insertions(+), 19 deletions(-) (limited to 'actionpack/lib/action_controller/request.rb') diff --git a/actionpack/lib/action_controller/request.rb b/actionpack/lib/action_controller/request.rb index af81f0775a..2cb4377273 100755 --- a/actionpack/lib/action_controller/request.rb +++ b/actionpack/lib/action_controller/request.rb @@ -1,6 +1,8 @@ module ActionController # These methods are available in both the production and test Request objects. class AbstractRequest + cattr_accessor :relative_url_root + # Returns both GET and POST parameters in a single hash. def parameters @parameters ||= request_parameters.merge(query_parameters).merge(path_parameters).with_indifferent_access @@ -57,6 +59,16 @@ module ActionController def yaml_post? post_format == :yaml && post? end + + + # Returns true if the request's "X-Requested-With" header contains + # "XMLHttpRequest". (The Prototype Javascript library sends this header with + # every Ajax request.) + def xml_http_request? + env['HTTP_X_REQUESTED_WITH'] =~ /XMLHttpRequest/i + end + alias xhr? :xml_http_request? + # Determine originating IP address. REMOTE_ADDR is the standard @@ -120,20 +132,15 @@ module ActionController protocol == 'https://' end - # returns the interpreted path to requested resource after - # all the installation directory of this application was taken into account + # Returns the interpreted path to requested resource after all the installation directory of this application was taken into account def path - uri = request_uri - path = uri ? uri.split('?').first : '' - - # cut off the part of the url which leads to the installation directory of this app - path[relative_url_root.length..-1] + path = (uri = request_uri) ? uri.split('?').first : '' + path[relative_url_root.length..-1] # cut off the part of the url which leads to the installation directory of this app end - # returns the path minus the web server relative - # installation directory - def relative_url_root - @@relative_url_root ||= File.dirname(env["SCRIPT_NAME"].to_s).gsub /(^\.$|^\/$)/, '' + # Returns the path minus the web server relative installation directory + def relative_url_root(force_reload = false) + @@relative_url_root ||= File.dirname(env["SCRIPT_NAME"].to_s).gsub(/(^\.$|^\/$)/, '') end def port @@ -158,14 +165,6 @@ module ActionController @path_parameters ||= {} end - # Returns true if the request's "X-Requested-With" header contains - # "XMLHttpRequest". (The Prototype Javascript library sends this header with - # every Ajax request.) - def xml_http_request? - env['HTTP_X_REQUESTED_WITH'] =~ /XMLHttpRequest/i - end - alias xhr? :xml_http_request? - #-- # Must be implemented in the concrete request #++ -- cgit v1.2.3