Skip to main content

Chat Using Action Cable part 3 - Chatroom and ChatroomUsers Association

Ruby • Asked by RicePad

I've been playing around and trying to implement a chat such as slack as shown on Chris's screencast. On Chatroom index I'm able to Show, Edit, Join, and Leave. However, when I clicked on Show even though it redirects me to the right chatroom I'm not able to send messages in real time because I haven't clicked on "joined" prior to entering the chatroom as a member. Is there a way to join the room while I'm already on the chatroom.


            *** <td><%= link_to "Join", chatroom_chatroom_users_path(@chatroom), method: :post %></td>***

                <strong>Welcome to my chatroom:</strong>
                <%= %>

            <div data-behavior='messages' data-chatroom-id='<%= %>'>
                <% @messages.each do |message| %>
                    <%= render message %>
                <% end %>

            <%= form_for [@chatroom,] do |f| %>
                <%= f.text_area :body, rows: 1, class: "form-control", autofocus: true %>
            <% end %>

I've added ***

<%= link_to "Join", chatroom_chatroom_users_path(@chatroom), method: :post %>*** on chatroom's show page to join. pic: ![] !

but it crashes giving me this error:![]

Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 27,623+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.