7

我最近在我的 Rails 路由文件中添加了一个子域约束

constraints(:subdomain => 'new') do
  devise_for :customers do 
    get "/customers/sign_up" => "registrations#new"
    post "/customers" => "registrations#create"
    put "/customers/:id" => "registrations#update"
  end
  match '/' => 'roxy#index'
  namespace :roxy, :path => '/' do
    resources :customers
    resources :surveys
  end
end 

为了在本地测试子域路由约束,我将这一行添加到我的 hosts 文件中。

127.0.0.1       new.localhost.local

现在,我在浏览器中通过 URL new.localhost.local:3000 测试我的应用程序。加载每个页面大约需要 10 - 15 秒,这非常慢。如果我删除子域约束并转到 127.0.0.1:3000,那么一切都会变得又快又快。

我究竟做错了什么?我是 Rails 新手,所以请告诉我是否有更好的方法在 Rails 中进行子域路由,或者是否有需要配置的设置。

4

1 回答 1

7

弄清楚了。这与 Rails 或子域或瘦无关。事实证明,与其他 unixy-things 不同,OS X 为 mDNS 功能保留了 .local TLD。对于每个页面,在加载我的应用程序之前,DNS 解析都会超时。所以我只是将我的 /etc/hosts 文件更改为

127.0.0.1    new.localhost.dev

现在一切都很好。

阅读更多:http ://www.justincarmony.com/blog/2011/07/27/mac-os-x-lion-etc-hosts-bugs-and-dns-resolution/

于 2012-11-06T19:56:11.470 回答