Skip to content
Browse files

Allow default_url_options to be set on route set

  • Loading branch information...
1 parent 4d2470f commit 1cc2a61ea655fea246f4c3e22a9e4a494e99d952 @josh josh committed Mar 9, 2010
View
5 actionpack/lib/action_dispatch/routing/mapper.rb
@@ -180,6 +180,11 @@ def match(*args)
@set.add_route(*mapping)
self
end
+
+ def default_url_options=(options)
+ @set.default_url_options = options
+ end
+ alias_method :default_url_options, :default_url_options=
end
module HttpHelpers
View
4 actionpack/lib/action_dispatch/routing/route_set.rb
@@ -186,6 +186,7 @@ def #{selector}(*args)
attr_accessor :routes, :named_routes
attr_accessor :disable_clear_and_finalize, :resources_path_names
+ attr_accessor :default_url_options
def self.default_resources_path_names
{ :new => 'new', :edit => 'edit' }
@@ -196,6 +197,7 @@ def initialize
self.named_routes = NamedRouteCollection.new
self.resources_path_names = self.class.default_resources_path_names.dup
self.controller_namespaces = Set.new
+ self.default_url_options = {}
@disable_clear_and_finalize = false
clear!
@@ -404,6 +406,8 @@ def generate(options, recall = {}, extras = false)
RESERVED_OPTIONS = [:anchor, :params, :only_path, :host, :protocol, :port, :trailing_slash, :skip_relative_url_root]
def url_for(options)
+ options = default_url_options.merge(options || {})
+
handle_positional_args(options)
rewritten_url = ""
View
4 actionpack/test/dispatch/routing_test.rb
@@ -15,6 +15,8 @@ def self.matches?(request)
stub_controllers do |routes|
Routes = routes
Routes.draw do
+ default_url_options :host => "rubyonrails.org"
+
controller :sessions do
get 'login' => :new, :as => :login
post 'login' => :create
@@ -189,6 +191,8 @@ def test_login
assert_equal '/login', url_for(:controller => 'sessions', :action => 'create', :only_path => true)
assert_equal '/login', url_for(:controller => 'sessions', :action => 'new', :only_path => true)
+
+ assert_equal 'http://rubyonrails.org/login', Routes.url_for(:controller => 'sessions', :action => 'create')
end
end

0 comments on commit 1cc2a61

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