Rails 3-一个应用程序,多个域,如何为其中一个域实施不同的“根”路由? [英] rails 3 - one app, multiple domains, how implement a different 'root' route for one of the domains?

查看:76
本文介绍了Rails 3-一个应用程序,多个域,如何为其中一个域实施不同的“根”路由?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几个不同的域名都指向我在heroku上的应用程序,例如foo.com和bar.com都指向该应用程序。 (我们托管专门的博客页面,而foo.com是创建网页的用户所使用的域,而bar.com是博客页面所在的面向公众的域。)

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.)

所有用户编辑页面都具有Devise身份验证,并且foo.com上的 root是用户的仪表板页面。登录的用户可以在foo.com/reviewpage/USERID上预览其博客页面

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

每个用户帐户还具有唯一的友好网址名称,例如 acme -inc-dallas-tx

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

在面向公众的网页bar.com(但仅此一个域)上,我需要以某种方式映射

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

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

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

假设,这意味着我需要重新映射 root bar.com(但仅限bar.com)转到方法 find_friendly_url,该方法查找适当的页面并显示该页面。

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.

如果这是正确的进行方法。 ..我将如何为一个指向我的应用程序的唯一域重新映射 root?

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

推荐答案

我通常以

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

match "/" => "home#standard" 

或:

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

match "/" => "home#standard" 

创建的对象:

/(.: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.

这篇关于Rails 3-一个应用程序,多个域,如何为其中一个域实施不同的“根”路由?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆