0

我有一些严重的问题,我创建了多种语言选择,效果很好,但链接一直在变化。从http://localhost:3000/en/products我点击这样的链接开始

<%= link_to image_tag('en.png',:alt => 'description', :title =>  (I18n.t 'english') ), params.merge(:locale => :en) %>

一段时间后,我在应用程序内部导航并单击不同的链接

http://localhost:3000/manufacturer_products?locale=en&manufacturer=Christophel

我相信问题出在 routes.rb 文件中。

这是我的路线文件

 root :to => 'home#index'
    devise_for :admin_users, ActiveAdmin::Devise.config
  ActiveAdmin.routes(self)
  get "about_us/index"

namespace :products do
  resources :categories do
    resources :products
  end

  resources :products, only: :index
end

namespace :products do
  resources :manufacturs do
    resources :products
  end

  resources :products, only: :index
end
  get "about/index"
  match ":locale/products/search" => "products#search"
  match "/contacts", to: "contacts#index"
  match "/products", to: "products#index"
  match "/home", to: "home#index"
  match "/about_us", to: "about_us#index"
  match "/news", to: "news#index"
  match "/manufacturer_products", to: "manufacturer_products#index"

match '/:locale' => 'home#index'
scope "(:locale)", :locale => /en|lv|ru/ do
 resources :products, :manufacturers, :categories, :news, :ActiveAdmin, :manufacturer_products

end

我知道我必须以某种方式将 namespace:products 路由与 locale 路由合并,但我不知道从哪里开始,如果有人可以给我一个小费或 smth :)

谢谢

4

2 回答 2

0

我找到了解决方案,问题是在路线文件中我没有正确的路线顺序。这条路由处理我在文件末尾的语言环境的路由。所以它没有用。

scope "(:locale)", :locale => /en|lv|ru/ do
   resources :products, :manufacturers, :categories, :news, :ActiveAdmin, :manufacturer_products, :about_us, :contacts
end

我将此代码移动到文件的开头,现在它可以完美运行。:)

于 2013-08-28T10:03:09.470 回答
0

我认为你的路线不是问题。

params.merge(:locale => :lv) 具有加入2个哈希的功能,所以你应该使用类似的东西

参数[:locale] || :zh

于 2013-08-22T10:23:33.217 回答