Created
November 10, 2015 08:45
-
-
Save markandrewj/c0b6db1a206c371deb2d to your computer and use it in GitHub Desktop.
Basecamp-style subdomains in Rails: DHH
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1) Point *.example.com in your DNS setup to your server. | |
# | |
# 2) Setup an Apache vhost to catch the star pointer: | |
# | |
# <VirtualHost *:80> | |
# ServerName example.com | |
# ServerAlias *.example.com | |
# </VirtualHost> | |
# | |
# 3) Set the current account from the subdomain | |
class ApplicationController < ActionController::Base | |
before_filter :set_current_account | |
private | |
def set_current_account | |
@current_account = Account.find_by_subdomain!(request.subdomains.first) | |
end | |
end | |
# 4) Tie all top-level requests off the current account | |
class CustomersController < ApplicationController | |
def index | |
@customers = @current_account.customers | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment