views:

62

answers:

1

I am currently directing all traffic that is subdomained and/or cnamed to my site to a controller called external and a method called handler.

This has gotten really messy and I would like to clean it up. I would like all external requests to be handled the normal rails way ":controller/:action/:id" however, I want these controllers in their own folder, so there is no overlap in my main controllers. /controllers/external/controller_name.rb

Here's what I have so far:

  not_domain_regex = Regexp.new('\A(?!(' + SiteConfig::domain.gsub('.', '\.') + '))', true)
  is_domain_regex = Regexp.new('\A((' + SiteConfig::domain.gsub('.', '\.') + '))', true)
  map.connect(
    '*path',
    :controller => 'external',
    :action => 'handler',
    :conditions => {
    :domain => not_domain_regex
    }
  )
  map.connect(
    '*path',
    :controller => 'external',
    :action => 'handler',
    :conditions => {
    :domain  => is_domain_regex,
    :subdomain => /([a-z0-9\-\_]{1,100}[^www])/i
    }
  )

I am completely lost. So I would like to have functionality that would look like this:

map.connect(
  ':controller/:action/:id',
  :namespace => 'external',
  :conditions => {
  :domain => not_domain_regex
  }
)
A: 

Try http://github.com/mbleigh/subdomain-fu

siong1987