Don't Forget To Reserve Subdomains For Yourself
In a certain application I’m working on, each account gets a unique subdomain. Something that is important, that most people don’t mention when showing examples of how to do account subdomainage, is how to reserve some for yourself and what are some good ones to reserve.
Here is a simplified version of the model I’m using:
class Account < ActiveRecord::Base ReservedSubdomains = %w[admin blog dev ftp mail pop pop3 imap smtp stage stats status www] validates_exclusion_of :subdomain, :in => ReservedSubdomains, :message => 'is not allowed' end
Then in rSpec, I use the following to make sure that none of the reserved subdomains can be used. One note: the have_error_on in the code below is a matcher that is a part of the rspec-on-rails-matchers plugin.
describe Account do it "should not allow use of reserved subdomains" do Account::ReservedSubdomains.each do |subdomain| Account.new(:subdomain => subdomain).should have_error_on(:subdomain) end end end
So nothing too difficult is going on up there. In fact, it is just out of the box Rails. The key, and the reason I post this, is to remind you to protect some of the important subdomains like mail, pop and smtp and some of the less important ones like blog and status for yourself.