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

但它始终是定义它使用的第一条路线。第二个是永远不会定义的。

我怎样才能做到这一点。这是一个rails错误吗?

4

1 回答 1

0

Not sure about it being a rails bug or not, but have a look at https://github.com/francesc/rails-translate-routes it works well and may help achieving this.

于 2012-04-25T16:13:01.900 回答