2

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!

1 Answer 1

2

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 %>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.