I'm making a chat room now. On the screen to create a room, select the user to enter the room, but currently only current_user and another user can enter the room. Using check_box etc.
What if I want to have more than one user in my room?

Reference (chat room creation screen)
Link content

Corresponding source code
[View file of room creation page]

   New chat room 
<% = form_with model: @room, local: true do | f |%>
      <% = f.label: Chat room name, class:'chat-room-form__label'%>
      <% = f.text_field: name, class:'chat__room_name chat-room-form__input', placeholder:'Please enter the chat room name'%>
      <label class ='chat-room-form__label' for ='chat_room_ chat member'>chat member</label>
      <select name = "room [user_ids] []">
        <option value = "">Please select the user to chat with</option>
        <% User.where.not (id: current_user.id) .each do | user |%>
         <option value =<% = user.id% >><% = user.name%></option>
      <% end%>
      <input name = "room [user_ids] []" type = "hidden" value =<% = current_user.id% >>
      <% = f.submit class:'chat-room-form__action-btn'%>
<% end%>
class RoomsController
class UsersController
  • Answer # 1

    As shown below, by using collection_check_boxes, we were able to create a chuck box that can be chucked multiple times.

              1-1<% = f.collection_check_boxes: user_ids, User.where (grade: 1, class_number: 1) .all,: id,: name%>