public
Last active — forked from JonCrawford/gist:44415

  • Download Gist
gistfile1.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
# 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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.