You should check out subdomain-fu plugin. Here is a link to the
tutorial:
http://intridea.com/2008/6/23/subdomainfu-a-new-way-to-tame-the-subdomain
If you have a choice to deviate from sub-domains, then you can give
your your users sub-folders in place of sub-domains. In that case your
users will have
blogexample.com/username as their URL. This is very
easy to achieve with simple routing techniques. For example:
map.connect ':username/:year/:month', :controller => 'blogs', :action
=> 'index'
This route will send the user to your blogs controller's index action
and will also supply params[:username], params[:year] and params
[:month] variables to your action.
Some people don't prefer sub-domains because they are tricky with SEO.
-subbu