rails i18n passed params get lost

≡放荡痞女 提交于 2019-12-12 01:53:25

问题


I started using i18n with my app, but all the pages that i access by passing a parameter with the link_to isn't working.

so, let's say i'm currently on this page

/ar/browse?type=art

that i got to via clicking on this link_to

<%= link_to "/ART/", browse_url(:type => "art")%>

then i decided to change the language via clicking on this:

<%= link_to_unless_current "en", locale: 'en', :class => 'my-navbar-link' %>

after changing the language, that's what i get directed to

/en/browse?class=my-navbar-link

the type parameter get lost after i change the language. and as a result it doesn't direct me to the correct page

hope i made it clear. i'm not sure how i can fix it :/

thank you in advance.


回答1:


You are incorrectly passing arguments to link_to_unless_current. The following is what you need to do:

link_text = "en" # or whatever you like
html_class = "my-navbar-link"

link_to_unless_current link_text,
                       {locale: "en", type: params[:type]},
                       {class: html_class}

i.e. you need to separate the link options from the HTML options.



来源:https://stackoverflow.com/questions/29002068/rails-i18n-passed-params-get-lost

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!