현재 하위 도메인에 따라 경로 (특히 root
경로)를 지정하려고합니다. 하위 도메인이 subdomain
인 경우 controller#action1
으로 연결하려고합니다. 하위 도메인이 있지만 이 아닌 경우 controller#action2
으로subdomain
또는 www
이 아닌 경우; 하위 도메인이 www
이거나 지정되지 않은 경우 controller#action3
으로 변경하십시오.여러 하위 도메인에 대한 라우팅
MyApp::Application.routes.draw do
scope :constraints => { :subdomain => "subdomain" } do
match "/" => "controller#action1"
end
scope :constraints => lambda {|req| req.subdomain.present? && !%w(subdomain www).include?(req.subdomain) } do
match "/" => "controller#action2"
end
root :to => "controller#action3"
end
브라우징 (action1
및 action2
, 각각에가는) 예상대로 모두 작업 subdomain.myapp.com
에와 other.myapp.com
을 :
myapp.com
또는
www.myapp.com
하려고 할 때, 내가 얻을 : 나는
rake routes
을 실행하면
Routing Error
No route matches [GET] "/"
, 나는
/{:subdomain=>"subdomain", :controller=>"controller", :action=>"action1"}
/{:controller=>"controller", :action=>"action2"}
root/{:controller=>"controller", :action=>"action3"}
그래서 (추측) 같아요 /
두 경로가 있기 때문에 돈 '을 참조 하위 도메인을 지정하지 않으면 폴백 경로가 두 번째 일치를 시도하지만 제약 조건을 충족하지 못하고 실패합니다. 제대로 작동하려면 어떻게해야합니까?