Topic: Multiple Domains

What's the best way to assign a separate domain to a specific controller?

Should I be doing this in routes? Do I also need to configure Apache somehow?

Re: Multiple Domains

Check out the Request Routing plugin. It allows you to change the route depending on the domain.

Railscasts - Free Ruby on Rails Screencasts

Re: Multiple Domains

Something must be wrong with my setup. I installed the plugin and then set a custom route:

map.connect '/', :controller => 'hub',:conditions => { 
    :domain => 'www.otherdomain.com' }

Looking at my slicehost control panel, I have indeed set up the domain along with two A records (www and otherdomain.com). Not sure if some apache witchcraft is necessary here..

Re: Multiple Domains

Do both domains point to your Rails app?

Railscasts - Free Ruby on Rails Screencasts

Re: Multiple Domains

Yup!

Re: Multiple Domains

Been poking around with this a bit. Thinkin perhaps apache proxy is tha way to go. I tried this

ProxyRequests On
ProxyVia On

# Configure mongrel_cluster
<Proxy balancer://app_cluster>
     
BalancerMember http://127.0.0.1:8000

BalancerMember http://127.0.0.1:8001

Allow from all
</Proxy>

ProxyPass /special_controller/ http://www.otherdomain.com/
ProxyPassReverse /special_controller/ http://www.otherdomain.com/


But no worky sad

Last edited by pimpmaster (2007-06-14 14:38:22)

Re: Multiple Domains

So I sort of got it working with the plugin, but this weird thing happens..whenever I reload the page it alternates between my source root and my other-domain root.

this happens on both domains!

I sit here hitting refresh and watching it alternate between the two home pages.

Ugh..I havent slept in 48 hours..i think its quitting time

Re: Multiple Domains

Okay so I cant sleep... it turns out this is not a problem with the plugin...for some reason my routes are stubbornly clinging to my home controller even though its not specified anywhere. I can put any other controller in there as my root route, but it just alternates between that and my home controller..

Edit: This is only the case on my production app. So i reverted my apache config... no weird proxies or rewrite rules whatsoever, but this annoying glitch wont go away..the homepages keep switching back and forth. I will need a straitjacket very soon if this keeps up

Last edited by pimpmaster (2007-06-14 21:08:22)

Re: Multiple Domains

So I found the problem. My mongrel cluster is very stubborn and does not die when I deploy or restart. I have to go into my remote box via SSH and manually kill the processes each time I want to restart.

Fisrt I show processes like this

ps awwwx | grep mongrel

Then it gives me a list of running mongrels, starting with numerical ID like 12345.

sudo kill 12345

For each one and then I can start my cluster without a hitch. This is super annoying and I need to get to the bottom of it, but at least I got this working now.

Thanks a bunch for tipping me on this plugin, Ryan.  smile

Re: Multiple Domains

Everything is running swell..though I find myself wishing that I could run a conditional check on domain inside my views.

Something like this would sure come in handy for my 404/500 error pages:

<% if current_domain == "site.com" %>
    # Custom Layout for Site
<% else %>
    # Custom Layout for Other Site
<% end %>

Ideas?

Last edited by pimpmaster (2007-06-18 12:42:15)

Re: Multiple Domains

Try this:

<% if request.host == "site.com" %>

Railscasts - Free Ruby on Rails Screencasts

Re: Multiple Domains

I just realized this probably won't work since I am dealing with html files for 404 and 500 pages.

Is it safe for me to replace these with rhtml files?

Re: Multiple Domains

You'll have to override the rescue_action_in_public method in your ApplicationController in order to do what you want. By default this method renders the 404.html and 500.html files.

Railscasts - Free Ruby on Rails Screencasts

Re: Multiple Domains

pimpmaster wrote:

Fisrt I show processes like this

ps awwwx | grep mongrel

Then it gives me a list of running mongrels, starting with numerical ID like 12345.

sudo kill 12345

For each one and then I can start my cluster without a hitch. This is super annoying and I need to get to the bottom of it, but at least I got this working now.

Thanks a bunch for tipping me on this plugin, Ryan.  smile

Maybe killall command is avaibable. Saves time.

Best Regards

Last edited by HerrK (2007-06-18 14:11:59)