I want to see messages in real time

"[Rails6.0] Real-time chat creation with ActionCable and Devise greedy set (revised version)"

We make community type sns with rails based on this article.
And, community creation function was added to this.

Message is not displayed at the front

It looks like the data is stored on the server.
I'm in trouble because the sent message doesn't appear.

Add community creation feature,
I confirmed the behavior after sending a message in the created community
The message is no longer updated in real time.

Before creating the community, it worked fine,

Applicable source code


class CommunityChannel</pre>
<p><br />
<pre><code>import consumer from './consumer'
$(function () {
  const chatChannel = consumer.subscriptions.create ({channel: 'CommunityChannel', community: $('# messages'). data ('community_id')}, {
    connected () {
      // Called when the subscription is ready for use on the server
    disconnected () {
      // Called when the subscription has been terminated by the server
    received: function (data) {
      return $('# messages'). append (data ['message']);
    speak: function (message) {
      return this.perform ('speak', {
        message: message
// keypress where data-behavior is community_speaker ...
  $(document) .on ('keypress', '[data-behavior ~ = community_speaker]', function (event) {
    if (event.keyCode === 13) {
      chatChannel.speak (event.target.value);
      event.target.value = '';
      return event.preventDefault ();


class MessageBroadcastJob</pre>
<p><br />
  <% = render @messages%>

<% = label_tag: content, @ community.name%>
<% = text_field_tag: content, nil, data: {behavior: 'community_speaker'}%>


  <p><% = "# {message.user.email}: # {message.content}"%></p>
What I did.

turbolinks removed.

  • Answer # 1

    It was a spelling error.
    Changed as follows.

    class MessageBroadcastJob

Related articles