Skip to content

Commit

Permalink
incorporate suggestion for 'Using Subdomains in Emails' from Tom Howlett
Browse files Browse the repository at this point in the history
  • Loading branch information
fortuity committed Sep 15, 2010
1 parent 9715010 commit 2a0ba64
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
19 changes: 19 additions & 0 deletions TUTORIAL.textile
Expand Up @@ -1011,6 +1011,24 @@ class SitesController < ApplicationController
end end
</pre> </pre>


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*:

<pre>
def set_mailer_url_options
ActionMailer::Base.default_url_options[:host] = with_subdomain(request.subdomain)
end
</pre>

and modify the file *app/controllers/application_controller.rb* to add:

@before_filter :set_mailer_url_options@

(Thanks to "Tom Howlett":http://solittlecode.com/ for this contribution.)

h2. Ignore a "www" Subdomain h2. Ignore a "www" Subdomain


At this point, if we visit "http://www.lvh.me:3000/":http://www.lvh.me:3000/ our application will look for a site with the subdomain "www" which doesn't exist. Instead this should redirect to the main home page. At this point, if we visit "http://www.lvh.me:3000/":http://www.lvh.me:3000/ our application will look for a site with the subdomain "www" which doesn't exist. Instead this should redirect to the main home page.
Expand Down Expand Up @@ -1187,3 +1205,4 @@ h4. Contributors


Thank you to contributor Fred Schoeneman for improving the tutorial. 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 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 change: 1 addition & 0 deletions app/controllers/application_controller.rb
Expand Up @@ -2,6 +2,7 @@ class ApplicationController < ActionController::Base
include UrlHelper include UrlHelper
protect_from_forgery protect_from_forgery
before_filter :limit_subdomain_access before_filter :limit_subdomain_access
before_filter :set_mailer_url_options


protected protected


Expand Down
5 changes: 5 additions & 0 deletions app/helpers/url_helper.rb
Expand Up @@ -11,4 +11,9 @@ def url_for(options = nil)
end end
super super
end end

def set_mailer_url_options
ActionMailer::Base.default_url_options[:host] = with_subdomain(request.subdomain)
end

end end

0 comments on commit 2a0ba64

Please sign in to comment.