2017-09-15 16 views
0

私の考えは、www.my-website.comに行くとwwwのような私の国のWebサイトへのリンクがある「国を選択」ランディングページを表示することです。 my-website.dk、www.my-website.deなどなどRails:ドメインに基づいて別のroot_toルートを選択する

私はこのようにroutes.rbをを作った:

MyApp::Application.routes.draw do 
    constraints subdomain: /\Awww\b/ do 
    apipie # For API documentation, see initializers/apipie.rb 
    draw :api_v1_v2_v3 
    draw :api 

    constraints ->(request) {request.host =~ /my-website\.com/ } do 
     root to: 'my_website_dot_com#landing_page' # anyone going to http://www.my-website.com/ will get this action 
    end 

    root to: 'my_website#front_page' 

    get 'sitemap', to: 'my_websiteouncle#sitemap' # anyone going to http://www.my-website.de/ or http://www.my-website.dk/ etc. will get this action 
    end 
end 

問題は私がどのようにレール4.2で複数のroot_toを持つことはできません、ですこの動作を達成するためにroutes.rbを変更することはできますか?

+0

を? –

答えて

0

私がやってしまった:あなたのサブドメイン用request.urlをテストし、それに応じてリダイレクトするアプリケーションのコントローラのメソッドを追加しないのはなぜ

constraints ->(request) { request.host =~ /my-website\.com$/ } do 
    get '/' => 'my_website_dot_com#landing_page', locale: :en 
end 

constraints ->(request) { !(request.host =~ /my-website\.com$/) } do 
    root to: 'my_website#front_page' 
end 
関連する問題