Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rails 3 - one app, multiple domains, how implement a different 'root' route for one of the domains?

Several different domains names point to my app on heroku, for example foo.com and bar.com both point to the app. (We host specialized blog pages, and foo.com is the domain used by our Users who are creating web pages, and bar.com is the 'public facing' domain where the blog pages are.)

All the user-editing pages have Devise authentication, and the "root" on foo.com is the User's dashboard page. And a logged-in user can preview their blog page at foo.com/reviewpage/USERID

each User acount also has a unique "friendly url name" such as "acme-inc-dallas-tx"

On the public-facing web page bar.com (but ONLY this one domain), I need to somehow map

http://bar.com/friendly-url-name to :controller => mycontroller, :action => myaction

I assume that means I need to re-map 'root' on bar.com (but ONLY bar.com) to a method "find_friendly_url" that looks up the appropriate page and displays it.

If that is the right way to proceed... how would I remap 'root' for one and only one domain that points to my app?

like image 395
jpw Avatar asked Jun 17 '11 21:06

jpw


1 Answers

I usually proceed as follows:

constraints(Subdomain) do
  match "/" => "home#admin"
end

match "/" => "home#standard" 

Or:

match "/" => "home#admin", :constraints => {:subdomain => "admin"}

match "/" => "home#standard" 

Which creates:

/(.:format) {:action=>"admin", :subdomain=>"admin", :controller=>"home"}
root  /(.:format) {:action=>"standard", :controller=>"home"}

The same logic lets you create routes only available to desired subdomains.

like image 137
apneadiving Avatar answered Oct 30 '22 11:10

apneadiving