Ruby on Rails:子域太强大了?我该如何正确设置
路线:
match '/' => 'site_admin/admin#index'
resources :link_pages
resources :services
resource :user_session
resource :account, :controller => "users"
resources :password_resets
resources :users
resources :addresses
resources :info
match "/home", :to => 'info#home'
match "/register", :to => 'users#new'
root :to => 'info#home'
match ':controller(/:action(/:id(.:format)))'
所以当我到达 admin.lvh.me:3000/ 时,它会转到 site_admin/admin#index...这很棒... 但是当我取消子域时,只有 lvh.me:3000/ 它会走相同的路线....
我如何让管理员保持在原来的位置。没有子域可以转到我的根页面,就像我的路由文件中那样?
routes:
match '/' => 'site_admin/admin#index'
resources :link_pages
resources :services
resource :user_session
resource :account, :controller => "users"
resources :password_resets
resources :users
resources :addresses
resources :info
match "/home", :to => 'info#home'
match "/register", :to => 'users#new'
root :to => 'info#home'
match ':controller(/:action(/:id(.:format)))'
so when I got to admin.lvh.me:3000/ it goes to site_admin/admin#index... which is great...
but when I take off the subdomain, and just have lvh.me:3000/ it goes to the same route....
how do I get admin to stay where it is. and no subdomain to go to my root page, as in my routes file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
路由按顺序解析,因此当您从任何域请求 / 时,它会首先找到“匹配'/'...”并将您发送到指定页面。您的子域根本不起作用。您可以使用基于请求的约束来基于子域进行路由:
http://guides。 rubyonrails.org/routing.html#request-based-constraints
Routes are parsed in order, so when you request / from any domain it finds "match '/'..." first and sends you to the specified page. Your subdomain isn't coming into play at all. You can use Request-based constraints to route based on subdomain:
http://guides.rubyonrails.org/routing.html#request-based-constraints
根本不知道子域是如何影响这个的。也许您将子域与路由命名空间混淆了(http://edgeguides.rubyonrails.org/routing.html#controller-namespaces-and-routing)?
被选择超过
因为它首先在路由文件中定义。它们表面上是同一件事。
Not sure how subdomain factors into this at all. Perhaps you're confusing subdomain with route namespacing (http://edgeguides.rubyonrails.org/routing.html#controller-namespaces-and-routing)?
Is being selected over
Because it's defined first in the routes file. They're ostensibly the same thing.
是的@Cory 是对的。上面两个语句是相似的,并且每次都会考虑第一个定义的路线。如果您将管理路由更改为
then it does make sense... What say??
或者,使用以下代码,您可以有条件地确定您的 URL:
will give you the subdomain value- either admin or blank. But it will go to any one controller action only which is defined first in route.rb file.
然后,从使用子域的操作中,您可以决定将其重定向到何处 - 管理面板或主页...
Yes @Cory is right. Above both statements are similar and first defined route is considered every time. If you change admin route to
then it does make sense... What say??
or else, using the following code you can determine your URL conditionally:
will give you the subdomain value- either admin or blank. But it will go to any one controller action only which is defined first in route.rb file.
Then from that action using subdomain, you can decide where to re-direct it- either to admin panel or home page...