I have a question I'm a little embarrassed to ask, but can't seem to figure out.
I'm writing a form to allow users to filter information for them to see only what they want. In the form I'm using the select_tag helper for a drop down menu. The selection menu is populated by an array of users. I have the following code:
<% @users.each do |user| %>
<%= select_tag "users", options_for_select([user.name]) %>
<% end %>
The problem with this, is it yields a selection menu for every user.name in the @users array. I assume the problem is that I'm using .each on my @users. However, I've been struggling with this too long this morning so I figured I'd just ask...
What's the proper way to get items from an array to populate into a single tag while using the select_tag helper?
Thanks
You don't have to loop through the users. You can just do this:
<%= select_tag "users", options_from_collection_for_select(@users, "id", "name") %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With