This project is archived and is in readonly mode.
default_url_options is a missing method
Reported by Damien MATHIEU | February 19th, 2010 @ 04:00 PM
The ActionMailer::Base's documentation says we should use
config.action_mailer.default_url_options = { :host => "example.com" }
To define the host for the links created in mails.
However when using this in config/environments/.rb, it says the
method default_url_options doesn't exists.
More to that, there's something odd here as there's already the
defaults
method, which allows us to define default
params.
Why should this method be different from the default params ?
Shouldn't it be better to define the url with
config.action_mailer.default :url_options => { :host => "example.com" }
Instead of having two different but similar methods (one of them which doesn't exists for now).
Comments and changes to this ticket
-
José Valim February 21st, 2010 @ 12:18 PM
I cannot reproduce this failure on rails master. I just added:
config.action_mailer.default_url_options = { :host => "example.com" }
To "config/environments/development.rb" and it worked as expected. Could you provide more information to reproduce the bug?
And the reason we have both :default and :default_url_options it's because they are difference concerns. :default is about your e-mail headers (like :from, :bcc and so on). default_url_options comes from ActionController::UrlFor.
-
trevor February 21st, 2010 @ 09:25 PM
+1
i've run into this too and don't know what the updated API is supposed to be.
after adding
ActionMailer::Base.default_url_options[:host] = "example.com"
toapplication.rb
-% rails -v Rails 3.0.0.beta % rc /usr/local/lib/ruby/gems/1.9.1/gems/actionmailer-3.0.0.beta/lib/action_mailer/deprecated_api.rb:72:in `method_missing': undefined method `default_url_options' for ActionMailer::Base:Class (NoMethodError) from /usr/local/lib/ruby/gems/1.9.1/gems/actionmailer-3.0.0.beta/lib/action_mailer/base.rb:344:in `method_missing' from /private/tmp/myapp/config/application.rb:7:in `<top (required)>' from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.0.beta/lib/rails/commands.rb:33:in `require' from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.0.beta/lib/rails/commands.rb:33:in `<top (required)>' from /private/tmp/myapp/script/rails:10:in `require' from /private/tmp/myapp/script/rails:10:in `<main>'
after adding
config.action_mailer.default_url_options = { :host => "example.com" }
toapplication.rb
-% rc /usr/local/lib/ruby/gems/1.9.1/gems/actionmailer-3.0.0.beta/lib/action_mailer/deprecated_api.rb:72:in `method_missing': undefined method `default_url_options=' for ActionMailer::Base:Class (NoMethodError) from /usr/local/lib/ruby/gems/1.9.1/gems/actionmailer-3.0.0.beta/lib/action_mailer/base.rb:344:in `method_missing' from /usr/local/lib/ruby/gems/1.9.1/gems/actionmailer-3.0.0.beta/lib/action_mailer/railtie.rb:17:in `block (2 levels) in <class:Railtie>' from /usr/local/lib/ruby/gems/1.9.1/gems/actionmailer-3.0.0.beta/lib/action_mailer/railtie.rb:16:in `each' from /usr/local/lib/ruby/gems/1.9.1/gems/actionmailer-3.0.0.beta/lib/action_mailer/railtie.rb:16:in `block in <class:Railtie>' from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.0.beta/lib/rails/initializable.rb:25:in `instance_exec' from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.0.beta/lib/rails/initializable.rb:25:in `run' from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.0.beta/lib/rails/initializable.rb:55:in `block in run_initializers' from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.0.beta/lib/rails/initializable.rb:54:in `each' from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.0.beta/lib/rails/initializable.rb:54:in `run_initializers' from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.0.beta/lib/rails/application.rb:71:in `initialize!' from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.0.beta/lib/rails/application.rb:41:in `method_missing' from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.0.beta/lib/rails/commands/console.rb:26:in `start' from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.0.beta/lib/rails/commands/console.rb:8:in `start' from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.0.beta/lib/rails/commands.rb:34:in `<top (required)>' from /private/tmp/myapp/script/rails:10:in `require' from /private/tmp/myapp/script/rails:10:in `<main>'
this is what http://edgeapi.rubyonrails.org/classes/ActionMailer/Base.html has to say -
When using named routes you only need to supply the :host:<%= users_url(:host => "example.com") %>
You will want to avoid using the name_of_route_path form of named routes because it doesn‘t make sense to generate relative URLs in email messages.
It is also possible to set a default host that will be used in all mailers by setting the :host option in the ActionMailer::Base.default_url_options hash as follows:
ActionMailer::Base.default_url_options[:host] = "example.com"
This can also be set as a configuration option in config/environment.rb:
config.action_mailer.default_url_options = { :host => "example.com" }
(also note the documentation still references config/environment.rb, and should be updated to config/application.rb)
-
Aleksander Kamil Modzelewski February 22nd, 2010 @ 12:32 PM
This is a problem in the prerelease, but not in master. Perhaps related to #3857?
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>