我正在尝试在 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
发布评论