Ask A Question


You’re not receiving notifications from this thread.

Chat Using Action Cable part 3 - Chatroom and ChatroomUsers Association

RicePad asked in Ruby

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:![]

Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 79,047+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more.

    © 2023 GoRails, LLC. All rights reserved.