This project is archived and is in readonly mode.
Ensure ActionController::UrlWriter#default_url_options are unique across classes
-
Pratik
- Milestone cleared.
- Assigned user set to Pratik
- Title changed from [PATCH] Ensure ActionController::UrlWriter#default_url_options are unique across classes to Ensure ActionController::UrlWriter#default_url_options are unique across classes
-
Repository
- State changed from new to resolved
(from [32eeb3e5211a4a7bfc7a1d0aa0cab1486bed3581]) Ensure that when UrlWriter is included in multiple classes, the default_url_options of one don't affect the other. [#1277 Ensure ActionController::UrlWriter#default_url_options are unique across classes state:resolved]
Signed-off-by: Pratik Naik pratiknaik@gmail.com http://github.com/rails/rails/co...
-
Nathan de Vries
Thanks Pratik.
-
Paco Benavent
- Tag changed from 2.2, patch, url_rewriter to 2.2, 2.3, default_url_options, patch, urlwriter, url_rewriter
This solution breaks compatibility with previous version, where you could assign default_url_options for the whole app in a file in config/initializers, for example:
config/initializers/mailer_opts.rb:
ActionController::UrlWriter::default_url_options[:host] = 'localhost' ActionController::UrlWriter::default_url_options[:port] = 3000In 2.3 this raises the following error:
undefined method `default_url_options' for ActionController::UrlWriter:Module (NoMethodError)is there any alternative solution?
-
findchris
Same exact problem as Paco was encountered when upgrading to Rails 2.3.
+1
-
Paco Benavent
After inspecting Rails 2.3.2 source code, it seems that UrlWriter is only included in class ActionMailer::Base. So I suppose that changing the previous example to:
ActionMailer::Base.default_url_options[:host] = 'localhost' ActionMailer::Base.default_url_options[:port] = 3000or alternatively, in config/environment.rb:
config.action_mailer.default_url_options = { :host => 'localhost', :port => 3000 }it's enough if you are using it only for mailers.
But, looking at Nathan's example, if you want the same options both for mailer and sms you have to declare it twice. Not very DRY.
-
Nathan de Vries
@Paco Benavent: I think that's a non-issue, given that you are configuring two completely independent classes. The only other option is to modify the behavior of mattr_accessor such that the values are distinct for the original module, and each class the module is mixed into.
