Skip to content

Instantly share code, notes, and snippets.

@JonCrawford
Forked from anonymous/gist:44410
Created January 7, 2009 20:45
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save JonCrawford/44415 to your computer and use it in GitHub Desktop.
Save JonCrawford/44415 to your computer and use it in GitHub Desktop.
Improved! A slight alteratiion of DHH's dynamic subdomain technique.
# 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
# </VirtualHost>
#
# 3) Set the current account from the subdomain
class ApplicationController < ActionController::Base
before_filter :set_current_account
private
def set_current_account
# I personally prefer "request.subdomains.last" because I see people enter
# "www.subdomain.myapp.com" quite often.
@current_account = Account.find_by_subdomain(request.subdomains.last)
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