処理に問題がある興味深いルーティング状況があります...これはRails2.3アプリの場合で、シナリオは次のとおりです。
route a:
/:trans_type/:country_code/:property_types
route b:
/:trans_type/:country_code/:location
これらの2つのルートはルート内の同じ場所を共有するため、2つを区別するために:locationまたは:property_typesのいずれかに:requirementを設定する必要があります。
:locationはかなり広く開かれているため、既存のすべてのプロパティタイプのリストを簡単にコンパイルして正規表現の照合を行うことができるモジュールがあるため、:property_typesが最適です。
問題:/ for-sale / us / apartment-loft
:property_typesは配列であるため、paramsオブジェクトから(明らかにルーターの外部で)複数のproperty_typesを解析する必要があります。このような場合、:property_typesはいくつかのハイフンでつながれたタイプを返す可能性があるため、ルーターで既知のプロパティタイプに対して正規表現の一致を行うことはできません。
私の質問は、:property_types文字列を取得して、:requirementsが一致するように特別に変更することは可能ですか?'apartment-loft'をその試合の'apartment'に置き換えることができれば(/ ^ \ w + /)、現実的に正規表現で対戦できるものがあります。
Here's what the two routes actually look like:
map.location ":transaction/:country_code/:property_types",
:controller => "search",
:action => "location",
:requirements => { :transaction => /(for-sale|for-rent|auction|new_development)/, :country_code => /\w\w/, :property_types => /(#{prop_types})/ }
map.location ":transaction/:country_code/:location",
:controller => "search",
:action => "location",
:requirements => { :transaction => /(for-sale|for-rent|auction|new_development)/, :country_code => /\w\w/}
上記の実装は、1つのproperty_typeを持つルートでは正常に機能しますが、複数のハイフンでつながれたproperty_typesを持つルートでは、壁にぶつかっています。