Rails i18n通过的参数迷路了 [英] rails i18n passed params get lost
问题描述
我开始在我的应用程序中使用 i18n ,但是通过使用 link_to 传递参数访问的所有页面均无法正常工作
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
通过点击此 link_to
that i got to via clicking on this link_to
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
我更改语言后,
type 参数丢失了.结果导致无法将我定向到正确的页面
hope i made it clear. i'm not sure how i can fix it :/
先谢谢您
推荐答案
您正在错误地将参数传递给link_to_unless_current
.以下是您需要做的:
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}
即您需要将链接选项与HTML选项分开.
i.e. you need to separate the link options from the HTML options.
这篇关于Rails i18n通过的参数迷路了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!