Many domain - one rails application

If I have many domains and one rails application, how can I redirect to
conrollers by domain?

Ex. “domain.com” go to controller “/com”, “domain.net” go to controller
“/net” and “other.org” go to “/other”

On Dec 17, 2007, at 2:42 PM, Ki Lo wrote:

If I have many domains and one rails application, how can I
redirect to
conrollers by domain?

Ex. “domain.com” go to controller “/com”, “domain.net” go to
controller
“/net” and “other.org” go to “/other”

You can extract the domain type from the request object (use
request.domain and split on the period to get the last element)

I probably wouldn’t write different controllers if the differences
are minor. If there is the need for multiple controllers, there’s
probably still one controller you initially interface to which can
change what it does based on the domain type (that is you pass the
domain type to the controller and let it make conditional decisions
– which might be factory pattern to launch a controller you describe
above).

You might find some useful thoughts here:
http://www.railsdev.ws/blog/10/using-subdomains-in-rails-apps/


def gw
acts_as_n00b
writes_at(www.railsdev.ws)
end

On 18 Dec 2007, at 11:29, Greg W. wrote:

request.domain and split on the period to get the last element)
You might find some useful thoughts here:
http://www.railsdev.ws/blog/10/using-subdomains-in-rails-apps/

The account_location plugin provides nice helpers for these kinds of
situations. However, a more appropriate solution in this case would
be to use apache’s rewrite functions to rewrite the request to point
to the correct controller. Saves you some conditioning and all the
problems that may arise from it in your rails app.

Best regards

Peter De Berdt

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs