title: Rails 5 Action Cable Not Working
body: <p>I've looked at multiple tutorials and cannot seem to receive notifications from action cable when I create a new Message record. All I am trying to do is print out the response in the console just so I know it works. I've installed redis but still no luck. Here are my files. Any help would be appreciated. </p>
  
  <p>cable.yml</p>
  
  <pre><code>redis: &amp;redis
  adapter: redis
  url: redis://localhost:6379/1
  
  production: *redis
  development: *redis
  test: *redis
  </code></pre>
  
  <p>application.js</p>
  
  <pre><code>//= require jquery
  //= require bootstrap-sprockets
  //= require rails-ujs
  //= require turbolinks
  //= require_tree ./channels
  </code></pre>
  
  <p>cable.js</p>
  
  <pre><code>// Action Cable provides the framework to deal with WebSockets in Rails.
  // You can generate new channels where WebSocket features live using the `rails generate channel` command.
  //
  //= require action_cable
  //= require_self
  //= require_tree ./channels
  
  (function() {
    this.App || (this.App = {});
  
    App.cable = ActionCable.createConsumer();
  
  }).call(this);
  </code></pre>
  
  <p>messages.js</p>
  
  <pre><code>//= require cable
  //= require_self
  
  (function() {
      // Subscrive to the class name of the channel
      App.messages = App.cable.subscriptions.create('MessagesChannel', {
      /**
       * Whenever this channel pushes content, it is received here
       */
      received: function(message) {
          console.log(message);
  
      }
    });
  }).call(this);
  </code></pre>
  
  <p>channels/messages.rb</p>
  
  <pre><code>class MessagesChannel &lt; ApplicationCable::Channel
    def subscribed
      stream_from 'messages'
    end
  end
  </code></pre>
  
  <p>models/message.rb</p>
  
  <pre><code>class Message &lt; ApplicationRecord
  
      after_save :broadcast_save
  
      def broadcast_save
         ActionCable.server.broadcast 'messages', html: render_task
      end
  
      private
      def render_task
         ApplicationController.render(partial: 'messages/message', locals: { message: self })
      end
    end
  </code></pre>
  
  <p>application.html.erb head element</p>
  
  <pre><code> &lt;head&gt;
      &lt;title&gt;Test&lt;/title&gt;
      &lt;%= action_cable_meta_tag %&gt;
      &lt;%= csrf_meta_tags %&gt;
      &lt;%= javascript_include_tag "//static.twilio.com/libs/twiliojs/1.2/twilio.min.js" %&gt;
      &lt;%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track': 'reload' %&gt;
      &lt;%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %&gt;
  
    &lt;/head&gt;
  </code></pre>
  
  <p>For testing purposes, I just create a new message when the controller action is called. </p>
  
  <pre><code>class PhoneController &lt; ApplicationController
  
      def index
          @tickets = []
          Message.create(body: "Test")
      end
  end
  </code></pre>
  
  <p>console output for rails</p>
  
  <pre><code>Started GET "/phone" for 75.65.92.24 at 2017-11-08 00:54:15 +0000
  Cannot render console from 75.65.92.24! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
  Processing by PhoneController#index as HTML
     (0.1ms)  BEGIN
    SQL (0.7ms)  INSERT INTO "messages" ("body", "created_at", "updated_at") 
  VALUES ($1, $2, $3) RETURNING "id"  [["body", "Test"], ["created_at", "2017-
  11-08 00:54:15.192006"], ["updated_at", "2017-11-08 00:54:15.192006"]]
    Rendered messages/_message.html.erb (0.5ms)
  [ActionCable] Broadcasting to messages: {:html=&gt;"asdf"}
     (5.4ms)  COMMIT
    Rendering phone/index.html.erb within layouts/application
    Rendered phone/index.html.erb within layouts/application (0.8ms)
  Completed 200 OK in 77ms (Views: 60.7ms | ActiveRecord: 6.3ms)
  </code></pre>
  
  <p>redis console output (last line)</p>
  
  <pre><code>[37939] 08 Nov 00:49:19.158 * The server is now ready to accept connections on port 6379
  </code></pre>