Ruby on rails url_如何从my routes.rb检查约束

Ruby on rails url_如何从my routes.rb检查约束,ruby-on-rails,routes,Ruby On Rails,Routes,我尝试在rails应用程序上定义一些转换路由。路由随子域定义而更改。所以我想要这个结果: describe "url_for" do context 'with en' do it 'brand translate' do url_for( :controller => 'boats', :action => 'index', :subdomain => :en,

我尝试在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_之间的唯一变化是子域。我尝试:

  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
但一直以来,它都是定义它使用的第一条路线。第二个是永不定义


我该怎么做呢。它是否是rails bug?

不确定它是否是rails bug,但看看它是否工作良好,可能有助于实现这一点。

我已经测试过这个gem,它工作正常,但不适用于url,如
”/yacht charter/brand-:brand
仅适用于
“/yacht charter/brand/:brand