2011-09-15 7 views
3

현재 하위 도메인에 따라 경로 (특히 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 

브라우징 (action1action2, 각각에가는) 예상대로 모두 작업 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"} 

그래서 (추측) 같아요 / 두 경로가 있기 때문에 돈 '을 참조 하위 도메인을 지정하지 않으면 폴백 경로가 두 번째 일치를 시도하지만 제약 조건을 충족하지 못하고 실패합니다. 제대로 작동하려면 어떻게해야합니까?

답변

1

이것은 라우팅 필터 젬의 버그 였고, 젬의 최신 버전과 Rails 3.2의 라우팅 변경 사항으로 수정 된 것으로 보입니다.

관련 문제