Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 3931

Show
Ignore:
Timestamp:
03/18/06 16:45:40 (2 years ago)
Author:
ulysses
Message:

Add ability for relative_url_root to be specified via an environment variable RAILS_RELATIVE_URL_ROOT. Closes #4243.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/CHANGELOG

    r3928 r3931  
    11*SVN* 
     2 
     3* Add ability for relative_url_root to be specified via an environment variable RAILS_RELATIVE_URL_ROOT. [isaac@reuben.com, Nicholas Seckar] 
    24 
    35* Fixed link_to "somewhere", :post => true to produce valid XHTML by using the parentnode instead of document.body for the instant form #3007 [Bob Silva] 
  • trunk/actionpack/lib/action_controller/request.rb

    r3850 r3931  
    164164 
    165165    # Returns the path minus the web server relative installation directory. 
    166     # This method returns nil unless the web server is apache. 
     166    # This can be set with the environment variable RAILS_RELATIVE_URL_ROOT. 
     167    # It can be automatically extracted for Apache setups. If the server is not 
     168    # Apache, this method returns an empty string. 
    167169    def relative_url_root 
    168       @@relative_url_root ||= server_software == 'apache' ? @env["SCRIPT_NAME"].to_s.sub(/\/dispatch\.(fcgi|rb|cgi)$/, '') : '' 
     170      @@relative_url_root ||= case 
     171        when @env["RAILS_RELATIVE_URL_ROOT"] 
     172          @env["RAILS_RELATIVE_URL_ROOT"] 
     173        when server_software == 'apache' 
     174          @env["SCRIPT_NAME"].to_s.sub(/\/dispatch\.(fcgi|rb|cgi)$/, '') 
     175        else 
     176          '' 
     177      end 
    169178    end 
    170179 
  • trunk/actionpack/test/controller/request_test.rb

    r3467 r3931  
    106106    @request.env['SCRIPT_NAME'] = "/collaboration/hieraki" 
    107107    assert_equal "/collaboration/hieraki", @request.relative_url_root     
     108     
     109    @request.relative_url_root = nil 
     110    @request.env['SCRIPT_NAME'] = "/hieraki/dispatch.cgi" 
     111    @request.env['SERVER_SOFTWARE'] = 'lighttpd/1.2.3' 
     112    @request.env['RAILS_RELATIVE_URL_ROOT'] = "/hieraki" 
     113    assert_equal "/hieraki", @request.relative_url_root 
     114     
     115    # @env overrides path guess 
     116    @request.relative_url_root = nil 
     117    @request.env['SCRIPT_NAME'] = "/hieraki/dispatch.cgi" 
     118    @request.env['SERVER_SOFTWARE'] = 'apache/1.2.3 some random text' 
     119    @request.env['RAILS_RELATIVE_URL_ROOT'] = "/real_url" 
     120    assert_equal "/real_url", @request.relative_url_root 
    108121  end 
    109122