rails params.merge in link_to [英] rails params.merge in link_to

查看:45
本文介绍了rails params.merge in link_to的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 link_to 块中添加 URL 参数.

I am trying to add a URL parameter in a link_to block.

当前代码 <%= link_to "Submit", :action =>'renderChart', :class =>"btn", :remote =>真,:params =>params.merge(:limit => 5) %>

但这给了我一个错误.

它将 :class 和 :action 添加到 url 参数中,而不仅仅是 :limit.为什么?

It adds the :class and :action into the url parameter, not just the :limit. Why?

我从另一个看起来像这样的链接添加了其他 URL 参数

I add other URL params from another link that looks like this

link_to "Toggle Sort Direction",:action => 'renderChart', :remote => true, :params => {:sort => "desc"}

所以当用户单击另一个链接时,我想将限制添加到 url 参数并保留排序参数

so when the user clicks the other link I want to add the limit to the url params and keep the sort params

推荐答案

我终于自己找到了解决方案.

I finally managed to get a solution myself.

如果我很简单地这样做::params =>{:限制=>..., :sort =>params[:sort]} 我得到了我所需要的.如果有一个排序参数,它会保持原样.

If I very simply do this: :params => {:limit => ..., :sort => params[:sort]} i get exactly what I need. If there is a sort param it keeps it the way it is.

这篇关于rails params.merge in link_to的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆