Code of simple rails, several applications addressed by domain name


I have a rails application which I would like to serve different sites distinguished by a domain name. Although the code is the same, the configuration is different. Probably the data for all applications will be placed in one database with different table prefixes. I am using rails3 and there defining table prefixes is possible (I did not check rails2 though, probably there also).

I tried to find similar questions about this topic, and although I found.. some negative answers, telling rails is not designed for that, but after rails 3 major release, maybe it is possible.. as it become more modular, and much cleaner, what I appreciate a lot.

My current idea to solve to the described problem is the following:

  1. when a request arrives, the middleware catches the domain name
  2. based on the domain name a prefix is identified, but naturally only for the actual request
  3. the activerecord's table_prefix reader will be changed, than it returns the prefix defined for the actual domain
  4. .. probably there will some other configurations which need to reflect on the actual domain

I would like to ask whether it is even worth of the effort to try. What are the possible pitfall I should recognize? Or are there already gems for the problem I am trying to address here? How would you try to solve this thing?

Thanks for your help!

What you really need to look at is how Rails manages call, through Rack.
Rack allows you to connect a valid web request to just about any Rack-compliant endpoint, like another Rails 3 app. You pass your data as :xml or :json to the other application.

I'm not sure how you would do this without having to replicate the data structure using an intermediary model in both applications. The downside is that you create and transfer several copies of the same data, so it would be lamely slow if you're dealing with a lot of information.