开发者

Ruby on Rails: subdomain too powerful? how do I set this up the right way

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 i开发者_运维知识库n my routes file?


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


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)?

match '/' => 'site_admin/admin#index'

Is being selected over

root :to => 'info#home'

Because it's defined first in the routes file. They're ostensibly the same thing.


Yes @Cory is right. Above both statements are similar and first defined route is considered every time. If you change admin route to

match '/admin' => 'site_admin/admin#index'
then it does make sense... What say??

or else, using the following code you can determine your URL conditionally:

request.subdomains(0).first
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...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜