【发布时间】:2014-06-08 04:37:34
【问题描述】:
我刚刚开始尝试更新我们的 rails 3.2 应用程序以实现国际化。我在路线中有一个可选范围,例如
范围“(:locale)”,语言环境:/en|es|zh-HK|de|fr/do
如http://guides.rubyonrails.org/i18n.html 所述。
我的网址助手喜欢
watch_url(@watch)
在表单中获取错误
没有路线匹配 {:action=>"show", :controller=>"watches", :locale=>#
"", "recipients"=>"", "attributes"=>""}, state: {}, hidden: false, comment: "">}
关于它为什么会发生以及如何解决它的任何想法?
谢谢!
编辑:
在我的应用程序控制器中,我有
before_filter :set_locale
def set_locale
I18n.locale = params[:locale] || I18n.default_locale
end
还有用于手表控制器的路由(这是一个已有 8 年历史的专有应用,我们有 100 多个控制器 :(,所以我不会包括所有路由)...
$ rake routes | grep watch
watches GET (/:locale)/watches(.:format) watches#index {:locale=>/en|es|zh-HK|de|fr/}
POST (/:locale)/watches(.:format) watches#create {:locale=>/en|es|zh-HK|de|fr/}
new_watch GET (/:locale)/watches/new(.:format) watches#new {:locale=>/en|es|zh-HK|de|fr/}
edit_watch GET (/:locale)/watches/:id/edit(.:format) watches#edit {:locale=>/en|es|zh-HK|de|fr/}
watch GET (/:locale)/watches/:id(.:format) watches#show {:locale=>/en|es|zh-HK|de|fr/}
PUT (/:locale)/watches/:id(.:format) watches#update {:locale=>/en|es|zh-HK|de|fr/}
DELETE (/:locale)/watches/:id(.:format) watches#destroy {:locale=>/en|es|zh-HK|de|fr/}
我不认为 show 方法是相关的。错误发生在 url 帮助程序中,并且流程永远不会到达显示代码。
【问题讨论】:
-
请发布您的
rake routes输出和controller的show方法。 -
你在 application.rb 中定义了你的 default_locale 吗?
标签: ruby-on-rails ruby-on-rails-3 internationalization rails-i18n