public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Allow ActionController::Base#default_url_options to have a default options 
argument of nil.

This fixes a bug introduced in [6a6b4392c16c665eb713705f2b38e959a658eeef] which 
was breaking routing in ActionController::UrlWriter.
chuyeow (author)
Sun May 04 08:54:08 -0700 2008
rick (committer)
Mon May 05 23:41:33 -0700 2008
commit  ee1d508a6bbdbfafb20516ebb4b452f1596f9ebe
tree    4bc2991c6819f50de9b44201033751baf9e27434
parent  04d85548608eb42f2d7071daa4661c5eac3a552a
...
998
999
1000
1001
 
1002
1003
1004
...
998
999
1000
 
1001
1002
1003
1004
0
@@ -998,7 +998,7 @@ module ActionController #:nodoc:
0
       # As you can infer from the example, this is mostly useful for situations where you want to centralize dynamic decisions about the
0
       # urls as they stem from the business domain. Please note that any individual url_for call can always override the defaults set
0
       # by this method.
0
-      def default_url_options(options) #:doc:
0
+      def default_url_options(options = nil)
0
       end
0
 
0
       # Redirects the browser to the target specified in +options+. This parameter can take one of three forms:
...
61
62
63
64
 
65
66
 
67
68
69
...
98
99
100
101
 
102
103
104
...
61
62
63
 
64
65
 
66
67
68
69
...
98
99
100
 
101
102
103
104
0
@@ -61,9 +61,9 @@ module ActionController
0
           # if they're using foo_url(:id=>2) it's one 
0
           # argument, but we don't want to generate /foos/id2
0
           if number_of_arguments == 1
0
-            "(!defined?(default_url_options) || default_url_options(nil).blank?) && defined?(request) && request && args.size == 1 && !args.first.is_a?(Hash)"
0
+            "(!defined?(default_url_options) || default_url_options.blank?) && defined?(request) && request && args.size == 1 && !args.first.is_a?(Hash)"
0
           else
0
-            "(!defined?(default_url_options) || default_url_options(nil).blank?) && defined?(request) && request && args.size == #{number_of_arguments}"
0
+            "(!defined?(default_url_options) || default_url_options.blank?) && defined?(request) && request && args.size == #{number_of_arguments}"
0
           end
0
         end
0
 
0
@@ -98,7 +98,7 @@ module ActionController
0
       # argument
0
       class PositionalArgumentsWithAdditionalParams < PositionalArguments
0
         def guard_condition
0
-          "(!defined?(default_url_options) || default_url_options(nil).blank?) && defined?(request) && request && args.size == #{route.segment_keys.size + 1} && !args.last.has_key?(:anchor) && !args.last.has_key?(:port) && !args.last.has_key?(:host)"
0
+          "(!defined?(default_url_options) || default_url_options.blank?) && defined?(request) && request && args.size == #{route.segment_keys.size + 1} && !args.last.has_key?(:anchor) && !args.last.has_key?(:port) && !args.last.has_key?(:host)"
0
         end
0
 
0
         # This case uses almost the same code as positional arguments, 
...
52
53
54
55
 
56
57
58
...
52
53
54
 
55
56
57
58
0
@@ -52,7 +52,7 @@ class DefaultUrlOptionsController < ActionController::Base
0
   def default_url_options_action
0
   end
0
 
0
-  def default_url_options(options)
0
+  def default_url_options(options = nil)
0
     { :host => 'www.override.com', :action => 'new', :bacon => 'chunky' }
0
   end
0
 end

Comments

samlown Mon Jun 09 09:07:31 -0700 2008

Hi,

This change has caused me a bit of a headache to try and figure why some of my redirects to named routes had stopped working after an upgrade to Rails 2.1. I’m probably not the only one to be affected by this either, as changing the definition of a method which is frequently “duck-typed” is really not a good idea, especially when the error message is so cryptic.

For the record the error I received was this:

(eval):2:in `default_url_options’ (eval):2:in `admin_pages_url’

Where admin_pages_url is my named route. The code in question in the controller was:

redirect_to admin_pages_url

Ensuring all definitions of default_url_options contain the options = nil part fixes this problem, but I really do not think this change was necessary.

Perhaps this can be reverted to the first version of this change here:

http://github.com/rails/rails/commit/6a6b4392c16c665eb713705f2b38e959a658eeef

Thanks, Sam Lown

samlown Mon Jun 09 09:07:38 -0700 2008

Hi,

This change has caused me a bit of a headache to try and figure why some of my redirects to named routes had stopped working after an upgrade to Rails 2.1. I’m probably not the only one to be affected by this either, as changing the definition of a method which is frequently “duck-typed” is really not a good idea, especially when the error message is so cryptic.

For the record the error I received was this:

(eval):2:in `default_url_options’ (eval):2:in `admin_pages_url’

Where admin_pages_url is my named route. The code in question in the controller was:

redirect_to admin_pages_url

Ensuring all definitions of default_url_options contain the options = nil part fixes this problem, but I really do not think this change was necessary.

Perhaps this can be reverted to the first version of this change here:

http://github.com/rails/rails/commit/6a6b4392c16c665eb713705f2b38e959a658eeef

Thanks, Sam Lown

samlown Mon Jun 09 09:07:42 -0700 2008

Hi,

This change has caused me a bit of a headache to try and figure why some of my redirects to named routes had stopped working after an upgrade to Rails 2.1. I’m probably not the only one to be affected by this either, as changing the definition of a method which is frequently “duck-typed” is really not a good idea, especially when the error message is so cryptic.

For the record the error I received was this:

(eval):2:in `default_url_options’ (eval):2:in `admin_pages_url’

Where admin_pages_url is my named route. The code in question in the controller was:

redirect_to admin_pages_url

Ensuring all definitions of default_url_options contain the options = nil part fixes this problem, but I really do not think this change was necessary.

Perhaps this can be reverted to the first version of this change here:

http://github.com/rails/rails/commit/6a6b4392c16c665eb713705f2b38e959a658eeef

Thanks, Sam Lown