本文介绍了通过Rails中的hidden_field_tag传递数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我确实在SO上找到了这个问题,但它没有真的没有帮助.
I did find this question on SO, but it didn't help, really.
所以,我想通过一个隐藏的字段标签传递一个数组.到目前为止,我的代码是:
So, I'd like to pass an array through a hidden field tag. As of now my code is:
<%= hidden_field_tag "article_ids", @articles.map(&:id) %>
这显然不起作用,因为它将id作为字符串传递.
This obviously does not work since it passes the ids as a string.
我该怎么做?
推荐答案
也许有更好的解决方案,但您可以尝试
Hi maybe there is better solution but you may try
<% @articles.map(&:id).each do |id| %>
<%= hidden_field_tag "article_ids[]", id %>
<% end %>
这篇关于通过Rails中的hidden_field_tag传递数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!