This project is archived and is in readonly mode.
Calling url_for with no arguments fails if default_url_options is not set
Reported by Luke Redpath | June 5th, 2008 @ 01:31 PM
Whilst upgrading an app from 1.2 to 2.1, one of my controller tests was failing with:
The error occurred while evaluating nil.[]
method rewrite_url in url_rewriter.rb at line 102
method rewrite in url_rewriter.rb at line 88
method url_for in base.rb at line 621
The reason for this failure is the way the case statement in url_for works:
### ActionController::Base
def url_for(options = nil) #:doc:
case options || {}
when String
options
when Hash
@url.rewrite(rewrite_options(options))
else
polymorphic_url(options)
end
end
If options is nil, it will run the case statement against the empty hash and call the "when Hash" branch, but options will still be nil so the rewrite call fails because it expects a hash.
The fix was quite simple (change the default options argument to {} instead of nil) and I've attached the fix as a patch with a test case.
Comments and changes to this ticket
-
Repository June 17th, 2008 @ 09:02 PM
- State changed from new to resolved
(from [a83ac48501aaba12b3d8abc0c6d6fdf0155de74d]) Fix url_for with no arguments when default_url_options is not explicitly defined. [#339 state:resolved]
Signed-off-by: Pratik Naik
-
Repository June 17th, 2008 @ 09:02 PM
(from [7650ff892cbffcaaaf9c5ab72466e98903a202d3]) Fix url_for with no arguments when default_url_options is not explicitly defined. [#339 state:resolved]
Signed-off-by: Pratik Naik
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>