diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-03-20 22:02:22 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-03-20 22:02:22 +0000 |
commit | a61360688cd0e1f43f523866384d0d0796a4ea73 (patch) | |
tree | dfa09275f2165b1af8363642b67d85b5702cf793 /actionpack/lib | |
parent | ee8d110068e958b400987b5f224e14e292fd0558 (diff) | |
download | rails-a61360688cd0e1f43f523866384d0d0796a4ea73.tar.gz rails-a61360688cd0e1f43f523866384d0d0796a4ea73.tar.bz2 rails-a61360688cd0e1f43f523866384d0d0796a4ea73.zip |
Changed .htaccess to allow dispatch.* to be called from a sub-directory as part of the push with Action Pack to make Rails work on non-vhost setups #826 [Nicholas Seckar/Tobias Luetke] Fixed routing and helpers to make Rails work on non-vhost setups #826 [Nicholas Seckar/Tobias Luetke]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@945 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib')
-rwxr-xr-x | actionpack/lib/action_controller/request.rb | 15 | ||||
-rw-r--r-- | actionpack/lib/action_controller/url_rewriter.rb | 7 | ||||
-rw-r--r-- | actionpack/lib/action_view/helpers/asset_tag_helper.rb | 26 |
3 files changed, 33 insertions, 15 deletions
diff --git a/actionpack/lib/action_controller/request.rb b/actionpack/lib/action_controller/request.rb index 429b3b9017..6e73a69ed7 100755 --- a/actionpack/lib/action_controller/request.rb +++ b/actionpack/lib/action_controller/request.rb @@ -84,9 +84,20 @@ module ActionController def ssl? protocol == 'https://' end - + + # returns the interpreted path to requested resource after + # all the installation directory of this application was taken into account def path - request_uri ? request_uri.split('?').first : '' + path = request_uri ? request_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] + end + + # returns the path minus the web server relative + # installation directory + def relative_url_root + File.dirname(env["SCRIPT_NAME"].to_s).gsub /(^\.$|^\/$)/, '' end def port diff --git a/actionpack/lib/action_controller/url_rewriter.rb b/actionpack/lib/action_controller/url_rewriter.rb index bbfa6009a4..3e6ccf7a06 100644 --- a/actionpack/lib/action_controller/url_rewriter.rb +++ b/actionpack/lib/action_controller/url_rewriter.rb @@ -2,13 +2,13 @@ module ActionController # Rewrites URLs for Base.redirect_to and Base.url_for in the controller. class UrlRewriter #:nodoc: - RESERVED_OPTIONS = [:anchor, :params, :only_path, :host, :protocol] + RESERVED_OPTIONS = [:anchor, :params, :only_path, :host, :protocol, :application_prefix] def initialize(request, parameters) @request, @parameters = request, parameters @rewritten_path = @request.path ? @request.path.dup : "" end - def rewrite(options = {}) + def rewrite(options = {}) rewrite_url(rewrite_path(options), options) end @@ -20,11 +20,12 @@ module ActionController private def rewrite_url(path, options) + rewritten_url = "" rewritten_url << (options[:protocol] || @request.protocol) unless options[:only_path] rewritten_url << (options[:host] || @request.host_with_port) unless options[:only_path] - rewritten_url << options[:application_prefix] if options[:application_prefix] + rewritten_url << (options[:application_prefix] || @request.relative_url_root) rewritten_url << path rewritten_url << "##{options[:anchor]}" if options[:anchor] diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb index 6328ff6f71..f6159e5246 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb @@ -33,8 +33,7 @@ module ActionView # <script language="JavaScript" type="text/javascript" src="/elsewhere/cools.js"></script> def javascript_include_tag(*sources) sources.collect { |source| - source = "/javascripts/#{source}" unless source.include?("/") - source = "#{source}.js" unless source.include?(".") + source = compute_public_path(source, 'javascripts', 'js') content_tag("script", "", "language" => "JavaScript", "type" => "text/javascript", "src" => source) }.join("\n") end @@ -49,8 +48,7 @@ module ActionView # <link href="/css/stylish.css" media="screen" rel="Stylesheet" type="text/css" /> def stylesheet_link_tag(*sources) sources.collect { |source| - source = "/stylesheets/#{source}" unless source.include?("/") - source = "#{source}.css" unless source.include?(".") + source = compute_public_path(source, 'stylesheets', 'css') tag("link", "rel" => "Stylesheet", "type" => "text/css", "media" => "screen", "href" => source) }.join("\n") end @@ -64,13 +62,11 @@ module ActionView # * full path, like "/my_images/image.gif" # * file name, like "rss.gif", that gets expanded to "/images/rss.gif" # * file name without extension, like "logo", that gets expanded to "/images/logo.png" - def image_tag(src, options = {}) + def image_tag(source, options = {}) options.symbolize_keys - - options.update({ :src => src.include?("/") ? src : "/images/#{src}" }) - options[:src] += ".png" unless options[:src].include?(".") - - options[:alt] ||= src.split("/").last.split(".").first.capitalize + + options[:src] = compute_public_path(source, 'images', 'png') + options[:alt] ||= source.split("/").last.split(".").first.capitalize if options[:size] options[:width], options[:height] = options[:size].split("x") @@ -79,6 +75,16 @@ module ActionView tag("img", options) end + + private + + def compute_public_path(source, dir, ext) + source = "/#{dir}/#{source}" unless source.include?("/") + source = "#{source}.#{ext}" unless source.include?(".") + source = "#{@request.relative_url_root}#{source}" + source + end + end end end |