Skip to content
Browse files

incorporate suggestion for 'Using Subdomains in Emails' from Tom Howlett

  • Loading branch information...
1 parent 9715010 commit 2a0ba6457959799a1376c9884de3b2405a0b38e3 @fortuity committed Sep 15, 2010
Showing with 25 additions and 0 deletions.
  1. +19 −0 TUTORIAL.textile
  2. +1 −0 app/controllers/application_controller.rb
  3. +5 −0 app/helpers/url_helper.rb
19 TUTORIAL.textile
@@ -1011,6 +1011,24 @@ class SitesController < ApplicationController
+h2. Using Subdomains in Emails
+Devise sends registration confirmations, forgotten password messages, and other email messages. These will originate from the main domain. You can modify the application so these emails originate from subdomains.
+Add the following code to the file *app/helpers/url_helper.rb*:
+def set_mailer_url_options
+ ActionMailer::Base.default_url_options[:host] = with_subdomain(request.subdomain)
+and modify the file *app/controllers/application_controller.rb* to add:
+@before_filter :set_mailer_url_options@
+(Thanks to "Tom Howlett": for this contribution.)
h2. Ignore a "www" Subdomain
At this point, if we visit "": our application will look for a site with the subdomain "www" which doesn't exist. Instead this should redirect to the main home page.
@@ -1187,3 +1205,4 @@ h4. Contributors
Thank you to contributor Fred Schoeneman for improving the tutorial.
Thank you to contributor Charlie Ussery for suggesting how to ignore the "www" subdomain.
+Thank you to contributor Tom Howlett for suggesting how to use subdomains in Devise emails.
1 app/controllers/application_controller.rb
@@ -2,6 +2,7 @@ class ApplicationController < ActionController::Base
include UrlHelper
before_filter :limit_subdomain_access
+ before_filter :set_mailer_url_options
5 app/helpers/url_helper.rb
@@ -11,4 +11,9 @@ def url_for(options = nil)
+ def set_mailer_url_options
+ ActionMailer::Base.default_url_options[:host] = with_subdomain(request.subdomain)
+ end

0 comments on commit 2a0ba64

Please sign in to comment.
Something went wrong with that request. Please try again.