Home>
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
[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%>
</select>
<input name = "room [user_ids] []" type = "hidden" value =<% = current_user.id% >>
<% = f.submit class:'chat-room-form__action-btn'%>
<% end%>
[Rooms.controller.rb]
class RoomsController
[Users.controller.rb]
class UsersController
-
Answer # 1
Related articles
- ruby on rails - rails error (logged out users see links that are no longer valid)
- ruby on rails 6 - if you use multiple link_to in rails6 helper, only the last one will be reflected
- ruby - i want to receive and search with multiple params
- ruby - i want to perform standard output with multiple lines and write/read multiple files
- ruby on rails multiple keyword search i don't know how to write
- ruby - when registering multiple images with rails, i would like to know the specific reason for managing the models separately
- ruby - i want to save multiple records in an intermediate table in one process
- ruby - rails json i want to get multiple resources at the same time
- java regarding the behavior when multiple users call the same method
- ruby sort multiple conditions?
- what happens when multiple java users call the same method
- ruby - [rails] i want to register data to multiple models with one form_with
- ruby - how to put and get the hash value in checkbox
- ruby - batch action for multiple selected data [rails]
- ruby - i want to register multiple records of the same model at the same time
- python - [django] i want multiple users to log in to the same site at the same time
- ruby - [rails] i want to add multiple records for each date and reflect them
- ruby - [rails] i want to get the latest multiple data from the database
- ruby - rails i want to search by multiple keywords
Related questions
- ruby - passing variables using render partial
- ruby - deployment error on heroku
- ruby - output the total integer value held by each user
- ruby - i want to use the search method for active hash data
- ruby - destroy action does not respond
- ruby - how do you see the rails controller relative path? (carrierwave directory deleted)
- ruby - when deploying on capistrano, i get the error "access denied for user'ec2-user' @'localhost' (using password: no)&qu
- javascript - run multiple times with js + each do
- how to reflect the layout downloaded from the external site in ruby on rails?
- ruby - how nice! function routes do not pass well (relation) [rails]
As shown below, by using collection_check_boxes, we were able to create a chuck box that can be chucked multiple times.