Skip to content
This repository
Browse code

Ensure request is present, as well as defined. [nzkoz]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7676 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 4953563e088bd23ef36ef4a76543deef5369fa9a 1 parent 26174b2
Michael Koziarski authored September 29, 2007
8  actionpack/lib/action_controller/routing_optimisation.rb
@@ -60,9 +60,9 @@ def guard_condition
60 60
           # if they're using foo_url(:id=>2) it's one 
61 61
           # argument, but we don't want to generate /foos/id2
62 62
           if number_of_arguments == 1
63  
-            "defined?(request) && args.size == 1 && !args.first.is_a?(Hash)"
  63
+            "defined?(request) && request && args.size == 1 && !args.first.is_a?(Hash)"
64 64
           else
65  
-            "defined?(request) && args.size == #{number_of_arguments}"
  65
+            "defined?(request) && request && args.size == #{number_of_arguments}"
66 66
           end
67 67
         end
68 68
 
@@ -75,7 +75,7 @@ def generation_code
75 75
             elements << '#{request.host_with_port}'
76 76
           end
77 77
 
78  
-          elements << '#{request.relative_url_root if request && request.relative_url_root}'
  78
+          elements << '#{request.relative_url_root if request.relative_url_root}'
79 79
 
80 80
           # The last entry in route.segments appears to # *always* be a
81 81
           # 'divider segment' for '/' but we have assertions to ensure that
@@ -97,7 +97,7 @@ def generation_code
97 97
       # argument
98 98
       class PositionalArgumentsWithAdditionalParams < PositionalArguments
99 99
         def guard_condition
100  
-          "defined?(request) && args.size == #{route.segment_keys.size + 1}"
  100
+          "defined?(request) && request && args.size == #{route.segment_keys.size + 1}"
101 101
         end
102 102
 
103 103
         # This case uses almost the Use the same code as positional arguments, 

0 notes on commit 4953563

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