I18n路由:缺少必需的密钥:[:locale]

时间:2014-11-18 14:37:26

标签: ruby-on-rails ruby ruby-on-rails-4 routes i18n-gem

使用Rails 4和I18n。

当我调用

之类的路径时
conversation_path(locale: :de, 1)

它给我一个错误说

No route matches {:action=>"show", :controller=>"frontend/conversations", :id=>1, :locale=>:de} missing required keys: [:locale]

的routes.rb

scope '/:locale' do
  localized do
    scope module: 'frontend' do
      resources :conversations, only: [:index, :show]
    end
  end
end

rake路线给了我

conversation_de GET /:locale/conversations/:id(.:format) frontend/conversations#show {:locale=>"de"}
conversation_en GET /:locale/conversations/:id(.:format) frontend/conversations#show {:locale=>"en"}
我错过了什么吗?

1 个答案:

答案 0 :(得分:1)

尝试更改routes.rb

scope '/:locale' do

为:

scope '/:locale', locale: /#{I18n.available_locales.join('|')}/ do