diff options
author | Vijay Dev <vijaydev.cse@gmail.com> | 2011-11-19 00:07:50 +0530 |
---|---|---|
committer | Vijay Dev <vijaydev.cse@gmail.com> | 2011-11-19 00:07:50 +0530 |
commit | dda6787f44a4e9a90cc28b3efee5b63c7d8cd023 (patch) | |
tree | 40da0b784665a167fed523639ee88ad7cb706d29 /railties/guides/source/action_mailer_basics.textile | |
parent | 48b580a03b84a277123b656efee91613f7503479 (diff) | |
download | rails-dda6787f44a4e9a90cc28b3efee5b63c7d8cd023.tar.gz rails-dda6787f44a4e9a90cc28b3efee5b63c7d8cd023.tar.bz2 rails-dda6787f44a4e9a90cc28b3efee5b63c7d8cd023.zip |
mailer guide - update info about using default host. Fixes #3642
Diffstat (limited to 'railties/guides/source/action_mailer_basics.textile')
-rw-r--r-- | railties/guides/source/action_mailer_basics.textile | 15 |
1 files changed, 4 insertions, 11 deletions
diff --git a/railties/guides/source/action_mailer_basics.textile b/railties/guides/source/action_mailer_basics.textile index ad5b848d2c..26c95be031 100644 --- a/railties/guides/source/action_mailer_basics.textile +++ b/railties/guides/source/action_mailer_basics.textile @@ -362,21 +362,14 @@ When using named routes you only need to supply the +:host+: Email clients have no web context and so paths have no base URL to form complete web addresses. Thus, when using named routes only the "_url" variant makes sense. -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: +It is also possible to set a default host that will be used in all mailers by setting the <tt>:host</tt> option as a configuration option in <tt>config/application.rb</tt>: <ruby> -class UserMailer < ActionMailer::Base - default_url_options[:host] = "example.com" - - def welcome_email(user) - @user = user - @url = user_url(@user) - mail(:to => user.email, - :subject => "Welcome to My Awesome Site") - end -end +config.action_mailer.default_url_options = { :host => "example.com" } </ruby> +If you use this setting, you should pass the <tt>:only_path => false</tt> option when using +url_for+. This will ensure that absolute URLs are generated because the +url_for+ view helper will, by default, generate relative URLs when a <tt>:host</tt> option isn't explicitly provided. + h4. Sending Multipart Emails Action Mailer will automatically send multipart emails if you have different templates for the same action. So, for our UserMailer example, if you have +welcome_email.text.erb+ and +welcome_email.html.erb+ in +app/views/user_mailer+, Action Mailer will automatically send a multipart email with the HTML and text versions setup as different parts. |