我有一个双语网站,有很好的 SEO 网址。使用 Ruby on Rails 2.3.10。
routes.rb
分段:
map.connect 'order-jira-hosting/:option.html',
:controller => 'order', :action => 'index', :locale => 'en'
map.connect 'order-jira-with-greenhopper-hosting/:option.html',
:controller => 'order', :action => 'index', :locale => 'en', :greenhopper => true
map.connect 'zamow-hosting-jira/:option.html',
:controller => 'order', :action => 'index', :locale => 'pl'
map.connect 'zamow-hosting-jira-z-greenhopper/:option.html',
:controller => 'order', :action => 'index', :locale => 'pl', :greenhopper => true
如您所见,:locale
并且:greenhopper
被“隐藏”在 URL 中。
有一个开关,您可以更改当前页面的语言。见我的views/layouts/default.erb
:
<%= link_to image_tag('icons/polish.png', :alt => 'polski'), { :locale => 'pl'}, :class => 'a' %>
<%= link_to image_tag('icons/english.png', :alt => 'English'), { :locale => 'en'}, :class => 'a' %>
我只是没有指定控制器和操作,因此我被重定向到具有不同语言环境的当前控制器和操作。不幸的是, :greenhopper 参数丢失了。
- 我在
/order-jira-with-greenhopper-hosting/11.html
(:option => 11, :locale => 'en', :greenhopper => true
) - 用于切换语言的生成链接是
/order-jira-hosting/11.html
和/zamow-hosting-jira/11.html
(:option => 11, :locale => 'pl' and 'en', :greenhopper => false)
... - ...但他们应该是
/order-jira-with-greenhopper-hosting/11.html
并且/zamow-hosting-jira-z-greenhopper/11.html
(:option => 11, :locale => 'pl' and 'en', :greenhopper => true)
如何使用 link_to 方法以保留传递给控制器的所有参数?谢谢你的帮助。