link_to 当前页面加上/与参数合并 [英] link_to the current page plus/merged with a param
问题描述
有点垒球问题,但我的 Google Fu 此刻让我逃过了一劫.
A bit of a softball question, but my Google Fu escapes me at the moment.
如何链接到当前页面,然后指定要合并到查询字符串中的参数?
How do I link to the current page but then specify params to be merged into the query string?
例如,如果当前页面是 /resources
,我希望能够指定诸如 current_page_plus(:param => 'attribute')
之类的东西来评估输出到 /resources?param=attribute
.
For instance, if the current page is /resources
, I want to be able to specify something like current_page_plus(:param => 'attribute')
that evaluates out to /resources?param=attribute
.
这也有望与现有属性合并,因此如果当前页面是 /resources?a=b&c=d
,则 current_page_plus(:c => 'e')
将评估为 /resources?a=b&c=e
.
This would hopefully also merge with existing attributes, so if the current page was /resources?a=b&c=d
, then current_page_plus(:c => 'e')
would evaluate to /resources?a=b&c=e
.
推荐答案
您可以使用 url_for
传递参数.
You can use url_for
passing the params.
url_for(params.merge(:c => "e"))
如果您使用像 link_to
这样内部使用 url_for
的助手,您可以跳过 url_for
并直接传递 has.
If you use an helper like link_to
that internally uses url_for
you can skip the url_for
and pass the has directly.
link_to "Page", params.merge(:c => "e")
这篇关于link_to 当前页面加上/与参数合并的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!