Rails_multi_view_per_host is a project mainly written in RUBY and JAVASCRIPT, it's free.
Rails multiple views per host, proof of concept
Given a request, depending on its host, the application should render a set of specific views.
Let's suppose that our domains in production are:
In order to test with those domains in the development environment we have to add a prefix localhost.
to the domains:
Also you have to add them into your /etc/hosts
file:
127.0.0.1 localhost.example1.com localhost.test2.com localhost.www.foodomain.com
The way it works is as follow:
set_site
(maybe the first before_filter
of your application), will check if the host is validapp/controllers/site_controller.rb
line #3)Now you can test the following URL's:
In order to do the same with the static resources, such as images, javascripts and stylesheets, it is possible to create a folder per host. For example:
public/
images/
domain1/
- image1.png
domain2/
- image1.png
<%= image_tag("images/domain1/image1.png") %>
or
<img src="/images/domain1/image1.png" />