views:

186

answers:

1

I'm successfully running subdomains on my mac OSX as outlined by Robby on Rails. I'd like to follow the example code below but I have no idea where to start. How do you edit a DNS setup? Do I need to have a dedicated virtual host to do this? Right now I have a standard (crappy) Dreamhost shared hosting. If I go with a DVH, is Media Temple a good pick?

Any media recs would be helpful - my google search's have only resulted in angry customer/hosting company tirades.

Thanks!

# 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
A: 

I do something similar with Heroku, which supports Wildcard DNS, definitely worth a look. There are a range of options for handling the DNS - most of the time this is actually handled by whoever is managing your name servers.

Dreamhost will allow Wildcard DNS hosting on request ... basically, they handle mapping incoming requests using their name servers, so not much for you to do other than send an email.

Toby Hede