Rails 3:子域路由
我正在尝试从rails 2.3.x(带有 subdomain_routes 插件)转换一些子域路由,如下所示:
map.subdomain :biz do |biz|
biz.resources :users
biz.resources :projects
biz.root :controller => 'home'
end
使用这些路由,我得到如下网址:
http://biz.example.com/users # :controller => 'biz/users', :action => 'index', :subdomain => 'biz'
使用rails3,没有 subdomain_routes 并且我无法创建相同类型的路线(即使我读过这是可能的)。尝试过这个:
scope :module => :biz, :as => :biz do
constraints(:subdomain => 'biz') do
resources :users
resources :projects
root :to => 'Biz::HomeController#index'
end
end
但是在控制台上尝试时,我没有得到子域,因此: 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
有什么建议吗?提前致谢;)
A.
I'm trying to convert some subdomain routes from rails 2.3.x (with subdomain_routes plugin) like these:
map.subdomain :biz do |biz|
biz.resources :users
biz.resources :projects
biz.root :controller => 'home'
end
with those routes, i got urls like this:
http://biz.example.com/users # :controller => 'biz/users', :action => 'index', :subdomain => 'biz'
with rails3, there isn't subdomain_routes and I can't create the same kind of routes (even if I've read that is possible). Tried with this:
scope :module => :biz, :as => :biz do
constraints(:subdomain => 'biz') do
resources :users
resources :projects
root :to => 'Biz::HomeController#index'
end
end
but when trying on console, I don't get subdomain, so for:
app.biz_users_url # http://www.example.com/users but not http://biz.example.com/users
I've also read/watched these resources, but there's no solution to my specific problem:
http://railscasts.com/episodes/221-subdomains-in-rails-3
http://yehudakatz.com/2009/12/26/the-rails-3-router-rack-it-up
any suggestions? thanks in advance ;)
A.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
上面的路由是正确的,主要问题是它们不能与 locahost 一起使用。使用 http://lvh.me (指向 127.0.0.1 的虚拟域)作为假域解决
the above routes are correct, tha main problem was that they doesn't work with locahost. solved using http://lvh.me (a virtual domain that points to 127.0.0.1) as fake domain
您可以通过以下调用获取带有子域的 URL app.biz_users_url(subdomain: 'biz')
You can get the URL with the subdomain making the following call app.biz_users_url(subdomain: 'biz')