Permalink
Browse files

Added :application_prefix to url_for and friends that makes it easier…

… to setup Rails in non-vhost environments #516 [Jamis Buck]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@494 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 45db66d commit 80b656637a29ce827b10923bb357cd56cde9b15f @dhh dhh committed Jan 24, 2005
View
@@ -1,5 +1,7 @@
*SVN*
+* Added :application_prefix to url_for and friends that makes it easier to setup Rails in non-vhost environments #516 [Jamis Buck]
+
* Added :encode option to mail_to that'll allow you to masquarede the email address behind javascript or hex encoding #494 [Lucas Carlson]
* Fixed that the content-header was being set to application/octet_stream instead of application/octet-stream on send_date/file [Alexey]
@@ -1,7 +1,7 @@
module ActionController
# Rewrites urls for Base.redirect_to and Base.url_for in the controller.
class UrlRewriter #:nodoc:
- VALID_OPTIONS = [:action, :action_prefix, :action_suffix, :module, :controller, :controller_prefix, :anchor, :params, :path_params, :id, :only_path, :overwrite_params, :host, :protocol ]
+ VALID_OPTIONS = [:action, :action_prefix, :action_suffix, :application_prefix, :module, :controller, :controller_prefix, :anchor, :params, :path_params, :id, :only_path, :overwrite_params, :host, :protocol ]
def initialize(request, controller, action)
@request, @controller, @action = request, controller, action
@@ -41,6 +41,7 @@ def rewrite_url(path, options)
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 << path
rewritten_url << build_query_string(new_parameters(options)) if options[:params] || options[:overwrite_params]
rewritten_url << "##{options[:anchor]}" if options[:anchor]
@@ -453,4 +453,25 @@ def test_rewriting_on_similar_fragments_with_action_prefixes
url.rewrite({ :controller => "msg", :action_prefix => "allous", :action => "new" })
)
end
+
+ def test_clean_application_prefix
+ assert_equal "http://www.singlefile.com/namespace/library/books/ISBN/0743536703/show",
+ @library_url.rewrite(:application_prefix => "/namespace")
+ end
+
+ def test_clean_application_prefix_with_controller_prefix
+ assert_equal "http://www.singlefile.com/namespace/shop/",
+ @library_url.rewrite(:application_prefix => "/namespace",
+ :controller_prefix => "shop" )
+ end
+
+ def test_blank_application_prefix
+ assert_equal "http://www.singlefile.com/library/books/ISBN/0743536703/show",
+ @library_url.rewrite(:application_prefix => "")
+ end
+
+ def test_nil_application_prefix
+ assert_equal "http://www.singlefile.com/library/books/ISBN/0743536703/show",
+ @library_url.rewrite(:application_prefix => nil)
+ end
end

0 comments on commit 80b6566

Please sign in to comment.