Is there a way to pass an array of object IDs through button_to
? I want the ID passed to controller in an array format so that it'll be the same format as if the user decides to select several items and click one submit button. On the page, there will be two options for selecting items but I want to the format of ID(s) passed to be the same to the controller. Thanks!
Asked
Active
Viewed 965 times
1

Jawa
- 2,336
- 6
- 34
- 39

sweetandsour
- 11
- 1
1 Answers
1
You can pass them through the url when using button_to:
<%= button_to 'Submit ids', resources_path(:ids => [1,2,3]) %>
Or generate a custom form with hidden fields instead of button_to (which in the end, is actually generating a form as well):
<%= form_tag resources_path do %>
<%= hidden_field_tag :ids, [1,2,3] %>
<%= submit_tag 'Submit ids' %>
<% end %>

polmiro
- 1,966
- 15
- 22