Permalink
Browse files

Tweak default_url_options deprecation warning

  • Loading branch information...
1 parent a04b449 commit a82cf0a9327d85f5787427e1d06d0ae374b11103 @jeremy jeremy committed Mar 5, 2010
Showing with 2 additions and 2 deletions.
  1. +2 −2 actionpack/lib/action_dispatch/routing/url_for.rb
@@ -152,7 +152,7 @@ def url_for(options = {})
when Hash
# Handle the deprecated instance level default_url_options
if respond_to?(:default_url_options, true)
- ActiveSupport::Deprecation.warn "Overwriting #default_url_options is deprecated. Please set url options with self.url_options = { ... }"
+ ActiveSupport::Deprecation.warn "Overriding the #default_url_options method is deprecated. Instead, set self.url_options = { ... } in a before_filter."
if defaults = default_url_options(options)
options = defaults.merge(options)
end
@@ -165,4 +165,4 @@ def url_for(options = {})
end
end
end
-end
+end

6 comments on commit a82cf0a

Member

josh replied Mar 6, 2010

This really sucks.

def default_url_options
  { :account_id => @account.id }
end

is way better than:

before_filter :set_default_url_options

def set_default_url_options
  self.url_options = { :account_id => @account.id }
end

Agreed, I guess an explanation of why this change is needed would help?

Owner

jeremy replied Mar 6, 2010

Then use

def url_options
  super :account_id => @account.id
end

Agreed that this may be better API than the instance writer runaround.

Can't you do something similar to AM where it does it's defaults hash?

class ApplicationController < ActionController::Base
  default_url_options :account_id => lambda { @account.id }
end
Owner

jeremy replied Mar 6, 2010

KieranP, using self.default_url_options at the controller class level remains the same, so yes.

Member

josh replied Mar 6, 2010

Does AC::Base#url_options have any significant options? Or it is just an empty hash?

def url_options
  { :account_id => @account.id }
end

could still work then.

Please sign in to comment.