2

我必须使用 rails url 帮助程序,而不是路径帮助程序(在某些情况下),因为我正在使用使用子域的应用程序,因此必须将 domain 选项作为参数传递。

然而,这导致链接呈现为:

http://sub.domain.dev/the-page?locale=en

我尝试在应用程序控制器中使用以下变体,但无济于事:

def default_url_options(options={})
  { :locale => :en }
end

如何删除该语言环境参数?

我正在使用炼油厂CMS。

4

3 回答 3

5

奇怪,但对于我这种情况的任何人:

当使用带有引擎的 RefineryCMS 时,即使没有使用区域设置,并且其他引擎产生预期的 url,修复是设置:

# config/initializers/refinery/i18n.rb
Refinery::I18n.configure do |config|
  config.enabled = false
end
于 2013-02-13T11:58:09.860 回答
1

对于炼油厂cms-i18n ~> 4.0:

# config/initializers/refinery/i18n.rb

Refinery::I18n.configure do |config|
  config.url_filter_enabled = false
end
于 2018-01-22T09:40:20.047 回答
0

如果您使用的是语言环境,我建议您执行以下操作:

在您的 routes.rb 中:

scope "(:locale)", locale: /en|br/ do
  resources :the-pages
end

在您的应用程序控制器中:

before_filter :set_locale
def set_locale
  I18n.locale = params[:locale]
end

def default_url_options(options={})
  { locale: I18n.locale }
end

这样,您的网址将变为:

http://sub.domain.dev/en/the-page
http://sub.domain.dev/pt/the-page

编辑- 如果您不想要任何语言环境,则需要将其从应用程序控制器中删除:

#remove the below
def default_url_options(options={})
 { :locale => :en }
end

另外,请确保您的 routes.rb 中没有任何语言环境

于 2013-02-13T10:03:16.783 回答