Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有没有办法传递对象 ID 数组button_to?我希望以数组格式将 ID 传递给控制器,以便它与用户决定选择多个项目并单击一个提交按钮时的格式相同。在页面上,将有两个选项用于选择项目,但我希望传递给控制器的 ID 格式相同。谢谢!
button_to
使用 button_to 时,您可以通过 url 传递它们:
<%= button_to 'Submit ids', resources_path(:ids => [1,2,3]) %>
或者生成一个带有隐藏字段而不是 button_to 的自定义表单(最终,它实际上也在生成一个表单):
<%= form_tag resources_path do %> <%= hidden_field_tag :ids, [1,2,3] %> <%= submit_tag 'Submit ids' %> <% end %>