Rails 3:子域路由

And*_*oni 7 subdomain routes ruby-on-rails-3

我正在尝试从rails 2.3.x(使用subdomain_routes插件)转换一些子域路由,如下所示:

map.subdomain :biz do |biz|
  biz.resources :users
  biz.resources :projects

  biz.root :controller => 'home'
end
Run Code Online (Sandbox Code Playgroud)

有了这些路线,我得到这样的网址:

http://biz.example.com/users # :controller => 'biz/users', :action => 'index', :subdomain => 'biz'
Run Code Online (Sandbox Code Playgroud)

使用rails3,没有subdomain_routes,我无法创建相同类型的路由(即使我已经阅读过可能).试过这个:

scope :module => :biz, :as => :biz do
  constraints(:subdomain => 'biz') do
    resources :users
    resources :projects
    root :to => 'Biz::HomeController#index'
  end
end
Run Code Online (Sandbox Code Playgroud)

但是在尝试使用控制台时,我没有获得子域名,所以对于:app.biz_users_url#http ://www.example.com/users 而不是http://biz.example.com/users

我也阅读/观看了这些资源,但我的具体问题没有解决办法:

http://railscasts.com/episodes/221-subdomains-in-rails-3 http://yehudakatz.com/2009/12/26/the-rails-3-router-rack-it-up

有什么建议?提前致谢 ;)

一个.

And*_*oni 9

以上路线是正确的,主要问题是它们不适用于locahost.使用http://lvh.me(一个指向127.0.0.1的虚拟域)作为伪域解决