Rails 3:子域路由

发布于 2024-10-09 21:48:13 字数 1267 浏览 1 评论 0原文

我正在尝试从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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

孤单情人 2024-10-16 21:48:13

上面的路由是正确的,主要问题是它们不能与 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

扭转时空 2024-10-16 21:48:13

您可以通过以下调用获取带有子域的 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')

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文