我有一个双语网站与良好的网址为SEO。使用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' %>我只是不指定控制器和操作,这样就可以重定向到具有不同区域设置的当前控制器和操作。不幸的是,温室参数丢失了。
/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方法来保存传递给控制器的所有参数?谢谢你的帮助。
发布于 2011-02-16 22:39:22
您可以将发送给link_to的散列建立在params散列的基础上,如果您按原样将其传递给link_to,将重新加载当前页面。您可以使用Hash.merge(other_hash)重置每个链接的:locale键:
<%= link_to '<polish image />', params.merge({:locale => 'pl'}), :class => 'a' %>现在,params确实包含控制器和操作键,但是它们是生成当前页面的控制器和操作,所以链接的行为应该像页面刷新一样,只有通过params.merge更改的参数才会发生变化。
希望这能有所帮助!
PS:params.merge不会更改params散列,如果您对此表示关注--合并的结果将作为新的哈希返回。
https://stackoverflow.com/questions/5022784
复制相似问题