0

レールに 2 つの異なるルートを設定しようとしていますが、それぞれが異なるサブドメインにリンクされています

これは私がしたいことのようなものです

match "/"  => "first_app#index",
              as => :first_app_root, 
              :subdomain => 'application' 

match "/"  => "second_app#index",
              :as => :second_app_root,  
              :subdomain => 'another_application' 

もちろん、取得したい結果application.my_websiteは、FirstAppController のインデックス アクションをanother_application.my_website.dev指し、SecondAppController のインデックス アクションを指すことです。

また、first_app_root_urlおよびsecond_app_root_urlヘルパー関数は、適切なサブドメインを含む URL を作成する必要があります

それは可能ですか?

4

1 に答える 1

1

これを match で実行したい場合は、次のステートメントで実行できるはずです。

match "/" => "first_app#index", :constraints => {:subdomain => "application"}
match "/" => "second_app#index", :constraints => {:subdomain => "another_application"}

しかし、よりクリーンな方法はおそらく

constraints :subdomain => "application" do
  # add your routes normally
end

constraints :subdomain => "another_application" do
  # add your routes normally
end

ドキュメント: http://guides.rubyonrails.org/routing.html#segment-constraints

于 2013-06-07T13:29:52.783 に答える