0

Rails アプリケーションでいくつかの変換ルートを定義してみます。サブドメインの定義でルートが変わります。だから私はこの結果が欲しい:

  describe "url_for" do
    context 'with en' do
      it 'brand translate' do
        url_for(
          :controller => 'boats',
          :action => 'index',
          :subdomain => :en,
          :brand => 'hello',                                                                                                                                                         
          :only_path => true
        ).should == '/yacht-charter/brand-hello'
      end
    end

    context 'with fr' do
      it 'brand translate' do
        url_for(
          :controller => 'boats',
          :action => 'index',
          :subdomain => :fr,
          :brand => 'hello',
          :only_path => true
        ).should == '/location-bateau/marque-hello'
      end 
    end   
  end

ご覧のとおり、両方の url_for パラメータ間の唯一の変更点はサブドメインです。私は試します:

  constraints => :subdomain => :en  do                                                                                                                   
    match '/yacht-charter/brand-:brand' => 'boats#index', :as => 'en_brand_search'
  end 

  constraints :subdomain => :fr do
    match '/location-bateau/marque-:brand' => 'boats#index', :as => 'fr_brand_search'
  end

しかし、常にそれが使用する最初のルート定義です。2 番目は決して定義されません。

どうやってやるの。それはレールのバグですか?

4

1 に答える 1

0

それがレールのバグであるかどうかはわかりませんが、https://github.com/francesc/rails-translate-routesを見てください。うまく機能し、これを達成するのに役立つかもしれません.

于 2012-04-25T16:13:01.900 に答える