All threads / Chat Using Action Cable part 3 - Chatroom and ChatroomUsers Association

Ask A Question

Notifications

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.

/views/chatrooms/show.html.erb

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

            <p>
                <strong>Welcome to my chatroom:</strong>
                <%= @chatroom.name %>
            </p>

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


            <%= form_for [@chatroom, Message.new] 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: ![http://prntscr.com/hj0egi] !

but it crashes giving me this error:![http://prntscr.com/hj0dfs]

Join the discussion

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

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

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

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.