rails params.merge in link

编程入门 行业动态 更新时间:2024-10-28 18:29:44
本文介绍了rails params.merge in link_to的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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

当前代码 '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

本文发布于:2023-10-09 17:50:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1476370.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:params   rails   link   merge

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!