1
votes

I have a dropdown select in a Rails form and I want to fill the dropdown menu with all of the user names of the registered users. Any ideas for how to go about doing this?

This is what I have so far:

<div class = "row">
  <div class = "form-group col-md-3">
    <%= f.label :room_number %><br>
    <%= f.select(:user_name, class: "dropdown-toggle") %>
  </div>
</div>
1

1 Answers

1
votes

You can go with:

<%= f.select :user_name, User.pluck(:name) %>

EDIT

to allow multiple selection, you would want to go with following:

 <%= f.select :user_name, User.pluck(:name), { multiple: true, size: 2 } %> #or any number