【发布时间】:2012-11-15 11:07:54
【问题描述】:
我知道这已经被问过了,但我仍然无法让它工作。
我正在尝试使用default_url_options 来显示:locale 参数,如下所示:
# SomethingController < ApplicationController
def default_url_options(options={})
{ :locale => I18n.locale }
end
I18n.locale 设置为 before_filter 并具有正确的值(使用 pry 进行调试)。
路线:
# In routes
scope "(:locale)", :defaults => { :locale => I18n.default_locale } do
get "something" => "something#index", :as => :something_index
end
在我看来我试过了:
url_for :something_index
和
something_index_url
但它们都返回“/something”而不是“/en/something”。为了自动显示要显示的参数,我还需要做些什么吗?
我读到了这个here:
每个依赖于 url_for 的辅助方法(例如,命名的辅助方法) root_path 或 root_url 之类的路由,books_path 之类的资源路由或 books_url 等)现在将自动在 查询字符串
【问题讨论】:
标签: ruby-on-rails-3