我正在开发一个Rails应用程序,默认情况下会将用户帐户设置为他们选择的子域。作为选项,他们将能够将自己的完整域映射到他们的帐户。如何将完整域映射到基于子域的Rails应用程序帐户?
到目前为止,这是我如何设置的东西。我使用subdomain-fu供电路由:
# routes.rb
map.with_options :conditions => {:subdomain => true} do |app|
app.resources # User's application routes are all mapped here
end
map.with_options :conditions => {:subdomain => false} do |www|
www.resources # Public-facing sales website routes are mapped here
end
除此之外,我使用的是method described here获得被访问的帐户,通过子域或全域:
before_filter :set_current_account
def set_current_account
if request.host.ends_with? current_domain
# via subdomain
@current_club = Club.find_by_subdomain(current_subdomain)
else
# via full domain
@current_club = Club.find_by_mapped_domain(request.host)
end
end
我没有已经远远落后于构建这个过程,但已经可以看到我将遇到路由问题。如果request.host
是一些random.com域,那么subdomain-fu不会路由适当的路线?
我假设这不是一个不寻常的问题,所以任何人都可以分享他们如何解决这个问题,或者我将如何配置我的路线去做我需要的东西?
谢谢您的回答。在试用另一个解决方案后,我得出结论,你是对的,为了简单起见,最好的办法是将其分成两个应用程序,并取消subdomain-fu。 – aaronrussell 2010-01-16 15:47:40