title: Rails app not showing notifications through ActionCable
body: <p>I have a todo-list rails app that allow one user to mark others users public lists as their favorite. The goal here is: when the owner of the list create a new todo-item, the users which mark that same list as their favorite should receive a notification in real time without refreshing the page.</p>
  
  <p><strong>app/assets/javascripts/channels/notification.js</strong></p>
  
  <pre><code>App.notifications = App.cable.subscriptions.create("NotificationsChannel", {
        connected: function() {
          // Called when the subscription is ready for use on the server
        },
  
        disconnected: function() {
          // Called when the subscription has been terminated by the server
        },
  
        received: function(data) {
          // Called when there's incoming data on the websocket for this channel
          $("#notifications").prepend(data.html);
        }
  </code></pre>
  
  <p>});</p>
  
  <p>My div in <strong>app/views/layouts/application.html.erb</strong></p>
  
  <pre><code>      &lt;body&gt;
            &lt;div class="container"&gt;
            &lt;div id="notifications"&gt;
  
            &lt;/div&gt;
            &lt;header&gt;
              &lt;div class="header_inner"&gt;
                &lt;nav style="text-align: right;"&gt;
                  &lt;% if user_signed_in? %&gt;
                    &lt;%= link_to 'New Todo List', new_todo_list_path %&gt; |
                    &lt;%= link_to "Sign out", destroy_user_session_path, method: :delete %&gt;
                  &lt;% else %&gt;
                    &lt;%= link_to "Log in", new_user_session_path %&gt;
                  &lt;% end %&gt;
                &lt;/nav&gt;
              &lt;/div&gt;
            &lt;/header&gt;
            &lt;%= yield %&gt;
          &lt;/div&gt;
        &lt;/body&gt;
  </code></pre>
  
  <p><strong>app/models/notification.rb</strong></p>
  
  <pre><code>class Notification &lt; ApplicationRecord
    after_create_commit { NotificationRelayJob.perform_later(self) }
  
    belongs_to :user
    belongs_to :recipient, class_name: "User"
    belongs_to :notifiable, polymorphic: true
  end
  </code></pre>
  
  <p><strong>app/models/todo_list.rb</strong></p>
  
  <pre><code>class TodoList &lt; ApplicationRecord
    belongs_to :user
    has_many :todo_items, dependent: :destroy
  
    has_many :favorites
    has_many :users, through: :favorites
  
    validates :title, presence: true
    validates :description, length: { maximum: 50 }
  
    def public?
      self.public
    end
  end
  </code></pre>
  
  <p><strong>app/views/notifications/todo_lists/_created.html.erb</strong></p>
  
  <pre><code>&lt;div&gt;&lt;%= notification.user.email %&gt; &lt;%= notification.action %&gt; new item!&lt;/div&gt;
  </code></pre>
  
  <p><strong>app/channels/notifications_channel.rb</strong></p>
  
  <pre><code>class NotificationsChannel &lt; ApplicationCable::Channel
    def subscribed
      stream_from "notifications:#{current_user.id}"
    end
  
    def unsubscribed
      stop_all_streams
    end
  end
  </code></pre>
  
  <p><strong>app/jobs/notification_relay_job.rb</strong></p>
  
  <pre><code>  class NotificationRelayJob &lt; ApplicationJob
    queue_as :default
  
    def perform(notification)
      html = ApplicationController.render partial: "notifications/#{notification.notifiable_type.underscore.pluralize}/#{notification.action}", locals: {notification: notification}, formats: [:html]
      ActionCable.server.broadcast "notifications:#{notification.current_user}", html: html
    end
  </code></pre>
  
  <p><strong>app/controllers/todo_items_controller.rb</strong></p>
  
  <pre><code>class TodoItemsController &lt; ApplicationController
    before_action :set_todo_list
    before_action :set_todo_item, except: [:create]
  
    def create
      @todo_item = @todo_list.todo_items.new(todo_item_params)
      if @todo_item.save
        @todo_list.users.each do |user|
          @noti = Notification.create(recipient: user, user: User.last, action: "create", notifiable: @todo_list)
        end
        redirect_to @todo_list, notice: 'Todo item added!'
      else
        redirect_to @todo_list, alert: 'Please some content in the new todo item'
      end
    end
    ...
  </code></pre>
  
  <p><strong>development.log</strong></p>
  
  <pre><code>web_1  | Finished "/cable/" [WebSocket] for 172.23.0.1 at 2018-04-17 00:58:28 +0000
  web_1  | NotificationsChannel stopped streaming from notifications:2
  web_1  | Started GET "/cable" for 172.23.0.1 at 2018-04-17 00:58:28 +0000
  web_1  | Cannot render console from 172.23.0.1! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
  web_1  | Started GET "/cable/" [WebSocket] for 172.23.0.1 at 2018-04-17 00:58:28 +0000
  web_1  | Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket)
  web_1  |   User Load (0.5ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ?  [["id", 2], ["LIMIT", 1]]
  web_1  | Registered connection (Z2lkOi8vZmFudGFzdGljLXN5c3RlbS9Vc2VyLzI)
  web_1  | NotificationsChannel is transmitting the subscription confirmation
  web_1  | NotificationsChannel is streaming from notifications:2
  web_1  | Started POST "/todo_lists/3/todo_items" for 172.23.0.1 at 2018-04-17 00:58:31 +0000
  web_1  | Cannot render console from 172.23.0.1! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
  web_1  | Processing by TodoItemsController#create as HTML
  web_1  |   Parameters: {"utf8"=&gt;"✓", "authenticity_token"=&gt;"WfKWJNbd0HiPj64/51vXsj7O/mJ7nF/U6tvwP5OQMsTLE0cgUQHXYq7D08bB3RUxuxqVTvcD6uGzWcNJqkxGQA==", "todo_item"=&gt;{"content"=&gt;"asd"}, "commit"=&gt;"Create Todo item", "todo_list_id"=&gt;"3"}
  web_1  |   TodoList Load (0.3ms)  SELECT  "todo_lists".* FROM "todo_lists" WHERE "todo_lists"."id" = ? LIMIT ?  [["id", 3], ["LIMIT", 1]]
  web_1  |    (0.1ms)  begin transaction
  web_1  |   SQL (2.2ms)  INSERT INTO "todo_items" ("content", "todo_list_id", "created_at", "updated_at") VALUES (?, ?, ?, ?)  [["content", "asd"], ["todo_list_id", 3], ["created_at", "2018-04-17 00:58:31.708390"], ["updated_at", "2018-04-17 00:58:31.708390"]]
  web_1  |    (157.7ms)  commit transaction
  web_1  |   User Load (0.4ms)  SELECT "users".* FROM "users" INNER JOIN "favorites" ON "users"."id" = "favorites"."user_id" WHERE "favorites"."todo_list_id" = ?  [["todo_list_id", 3]]
  web_1  |   User Load (0.3ms)  SELECT  "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT ?  [["LIMIT", 1]]
  web_1  |    (0.1ms)  begin transaction
  web_1  |   SQL (1.5ms)  INSERT INTO "notifications" ("user_id", "recipient_id", "action", "notifiable_type", "notifiable_id", "created_at", "updated_at") VALUES (?, ?, ?, ?, ?, ?, ?)  [["user_id", 3], ["recipient_id", 1], ["action", "followed"], ["notifiable_type", "TodoList"], ["notifiable_id", 3], ["created_at", "2018-04-17 00:58:31.915523"], ["updated_at", "2018-04-17 00:58:31.915523"]]
  web_1  |    (97.2ms)  commit transaction
  web_1  | [ActiveJob] Enqueued NotificationRelayJob (Job ID: a32e8a9d-d9fd-4a1c-90c1-891c48709b4b) to Async(default) with arguments: #&lt;GlobalID:0x00007f651054f610 @uri=#&lt;URI::GID gid://fantastic-system/Notification/72&gt;&gt;
  web_1  | Redirected to http://localhost:3000/todo_lists/3
  web_1  |   Notification Load (0.6ms)  SELECT  "notifications".* FROM "notifications" WHERE "notifications"."id" = ? LIMIT ?  [["id", 72], ["LIMIT", 1]]
  web_1  | Completed 302 Found in 359ms (ActiveRecord: 261.1ms)
  web_1  | 
  web_1  | 
  web_1  | [ActiveJob] [NotificationRelayJob] [a32e8a9d-d9fd-4a1c-90c1-891c48709b4b] Performing NotificationRelayJob (Job ID: a32e8a9d-d9fd-4a1c-90c1-891c48709b4b) from Async(default) with arguments: #&lt;GlobalID:0x00007f64cc04ab18 @uri=#&lt;URI::GID gid://fantastic-system/Notification/72&gt;&gt;
  web_1  | [ActiveJob] [NotificationRelayJob] [a32e8a9d-d9fd-4a1c-90c1-891c48709b4b]   User Load (0.4ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = ? LIMIT ?  [["id", 3], ["LIMIT", 1]]
  web_1  | [ActiveJob] [NotificationRelayJob] [a32e8a9d-d9fd-4a1c-90c1-891c48709b4b]   Rendered notifications/todo_lists/_followed.html.erb (4.9ms)
  web_1  | [ActiveJob] [NotificationRelayJob] [a32e8a9d-d9fd-4a1c-90c1-891c48709b4b] [ActionCable] Broadcasting to notifications:3: {:html=&gt;"&lt;div&gt;a@a.com.br followed you!&lt;/div&gt;\n"}
  web_1  | [ActiveJob] [NotificationRelayJob] [a32e8a9d-d9fd-4a1c-90c1-891c48709b4b] Performed NotificationRelayJob (Job ID: a32e8a9d-d9fd-4a1c-90c1-891c48709b4b) from Async(default) in 7.58ms
  web_1  | Started GET "/todo_lists/3" for 172.23.0.1 at 2018-04-17 00:58:32 +0000
  web_1  | Cannot render console from 172.23.0.1! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
  web_1  | Processing by TodoListsController#show as HTML
  web_1  |   Parameters: {"id"=&gt;"3"}
  web_1  |   TodoList Load (0.2ms)  SELECT  "todo_lists".* FROM "todo_lists" WHERE "todo_lists"."id" = ? LIMIT ?  [["id", 3], ["LIMIT", 1]]
  web_1  |   Rendering todo_lists/show.html.erb within layouts/application
  web_1  |   TodoItem Load (0.2ms)  SELECT "todo_items".* FROM "todo_items" WHERE "todo_items"."todo_list_id" = ?  [["todo_list_id", 3]]
  web_1  |   User Load (0.2ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = ? LIMIT ?  [["id", 2], ["LIMIT", 1]]
  web_1  |   User Load (0.5ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ?  [["id", 2], ["LIMIT", 1]]
  web_1  |   Rendered collection of todo_items/_todo_item.html.erb [4 times] (7.3ms)
  web_1  |   Rendered todo_items/_form.html.erb (2.8ms)
  web_1  |   Rendered todo_lists/show.html.erb within layouts/application (16.8ms)
  web_1  | Completed 200 OK in 47ms (Views: 44.4ms | ActiveRecord: 1.1ms)
  web_1  | 
  web_1  | 
  web_1  | Finished "/cable/" [WebSocket] for 172.23.0.1 at 2018-04-17 00:58:32 +0000
  web_1  | NotificationsChannel stopped streaming from notifications:2
  web_1  | Started GET "/cable" for 172.23.0.1 at 2018-04-17 00:58:32 +0000
  web_1  | Cannot render console from 172.23.0.1! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
  web_1  | Started GET "/cable/" [WebSocket] for 172.23.0.1 at 2018-04-17 00:58:32 +0000
  web_1  | Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket)
  web_1  |   User Load (0.4ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ?  [["id", 2], ["LIMIT", 1]]
  web_1  | Registered connection (Z2lkOi8vZmFudGFzdGljLXN5c3RlbS9Vc2VyLzI)
  web_1  | NotificationsChannel is transmitting the subscription confirmation
  web_1  | NotificationsChannel is streaming from notifications:2
  </code></pre>
  
  <p>I'm able to see all user that favorite a list through "@todo_list.users"(that will receive the notification), the console says that NotificationChannel is trasmitting and streaming, but nothing happens when I create a new todo item. I've been searching it for a while but it seens I not quite understand ActionCable very well :(.</p>
  
  <p>Any help is greatly appreciated.</p>