Skip to content
Browse files

Allowing for calling routes without a request, and just generally mak…

…ing this method a little more readable.
  • Loading branch information...
1 parent 7e48b9a commit cc3f229174c98ed7642a2c6743eb1ac990405470 @pat pat committed Sep 21, 2010
Showing with 9 additions and 5 deletions.
  1. +9 −5 lib/subdomain_fu/url_rewriter.rb
View
14 lib/subdomain_fu/url_rewriter.rb
@@ -4,15 +4,19 @@ module ActionDispatch
module Routing
class RouteSet #:nodoc:
def url_for_with_subdomains(options, path_segments=nil)
- if SubdomainFu.needs_rewrite?(options[:subdomain], (options[:host] || @request.host_with_port)) || options[:only_path] == false
+ host_with_port = options[:host]
+ host_with_port ||= @request.host_with_port unless @request.nil?
+ subdomain = options.delete(:subdomain)
+
+ if options[:only_path] == false || SubdomainFu.needs_rewrite?(subdomain, host_with_port)
options[:only_path] = false if SubdomainFu.override_only_path?
- options[:host] = SubdomainFu.rewrite_host_for_subdomains(options.delete(:subdomain), options[:host] || @request.host_with_port)
- else
- options.delete(:subdomain)
+ options[:host] = SubdomainFu.rewrite_host_for_subdomains(subdomain, host_with_port)
end
+
url_for_without_subdomains(options)
end
+
alias_method_chain :url_for, :subdomains
end
end
-end
+end

0 comments on commit cc3f229

Please sign in to comment.
Something went wrong with that request. Please try again.