I needed to be able to route any domain that was not my own to a single controller. And furthermore I had to route any subdomain that was not ” and not ‘www’ to that same controller.
If you can’t guess why, it is because it is a hosted application. In any case, I used the request_routing plugin and it seemed OK for my needs. The problem was, it didn’t accept things like :not => ‘www’ or :not => ”. So, I ended up using a regular expression for my result. Here goes.
-
not_domain_regex = Regexp.new(‘\A(?!(’ + AConfig::domain.gsub(‘.’, ‘\.‘) + ‘))’, true)
-
is_domain_regex = Regexp.new(‘\A((’ + AConfig::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
-
}
-
)
The next step in this will be to replace “*path” with “:controller/:action/:id” and have it route to namespaced controllers.
Ex:
/controllers/external/controller_name.rb
If you have any ideas on that part. Let me know
