Routing subdomain request

Give how to do this trick:

  1. Users were tables with one of the fields and table subdomain
    Blogs class Blog <ActiveRecord:: Base
    has_many: comments
    belongs_to: user
    class User <ActiveRecord:: Base
    has_many: blogs
  2. There is a module which writes in account_subdomain subdomain
    address from the browser
  3. The objective to have at domain.com / blogs drawing record all
    users, and sub.domain.com/blogs write only user’s subdomain which
    “sub” How? Thanks!