I would like to access one rails application through more virtual hosts. The different virtual hosts would differ in the database, images, stylesheets and in some cases the layout of the views. What do you recommend for realisation of serving multiple applications by one rails code, which is accessed through different virtual hosts?
Edited
To specify what I imagine better, I add these:
I am wondering which layer the rails app should recognise the host? Should it be on the middleware, in boot scripts or elsewhere?
For the database:
You can set an special parameter in the routes, like:
/:client/:controller/:action
and then use params[:client] to manually adjust ActiveRecord::Base.establish_connection(...) from an ApplicationController before_filter (I have done this an it works)
see sample code here: ruby-forum
For the stylesheets, images...: Use apache o nginx virtual host to diverge public/images and others (as yiou should do to serve the directly without rails) and choose there where you pick them from. (you may need mod_rewrite o equivalent for this)
Layouts may be a little bit more tricky, better have a common erb that loads partials wisefully depending on the params[:client].
I hope it helps.
I don't know rails but I know how I'd do it in Django. I doubt the core logic is that different.
I'd tell the server what hosts to accept (including wildcards, if I wanted) and then tell my webapp to look at the request domain (which is passed through from the webserver).
How you change various things from that point is up to you.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.