【发布时间】:2011-03-22 15:40:42
【问题描述】:
我将 i18n 添加到我的网页(不同语言的不同内容)。我的网址看起来像这样:
http://host.tld/de/news/15
http://host.tld/en/news/15
...
我在应用程序中的所有 URL 都是由 link_to/url_for 这样的方法设置的
url_for("/news/#{news.id}/#{urlify(news.title)}")
url_for("/news/#{@news.section}")
...
我的路由如下所示:
scope "/:language/", :language => /de|en/ do
match "news/:news_id(/:title)" => "news#show_entry", :constraints => { :news_id => /[0-9]+/ }
...
end
我将它添加到我的 ApplicationController:
def default_url_options(options={})
{:language => I18n.locale}
end
现在我想在不更改所有 url_for() 调用的情况下将语言前缀添加到所有 URL。有没有解决方案(参数/配置选项或其他东西)来添加这个前缀?它也应该适用于相对路径。
【问题讨论】:
标签: ruby-on-rails-3 scope url-routing