【发布时间】:2011-01-05 13:38:24
【问题描述】:
我正在开发一个 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 不会路由适当的路由?
我假设这不是一个不寻常的问题,所以任何人都可以分享他们是如何解决这个问题的,或者我将如何配置我的路线来做我需要的事情?
【问题讨论】:
标签: ruby-on-rails ruby routing subdomain