There is no activity with ActionCable rails 5.0.1

This isn't the first time I've installed WebSockets in Rails, but when I enter this code into my Rails console, nothing happens. It should print 'ok' in the Chrome console, right? The connected function works, but the message is not received. What could be wrong with this code? I tried replacing async with redis, but it didn't make any difference.

NotificationsChannel.broadcast_to(User.find_by(email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2256475156624f434b4e0c414d4f">[email protected]</a>"), title: "ok")

Logs in rails c

[ActionCable] Broadcasting to notifications:Z2lkOi8vZ2FtZS1saWJyYXJ5L1VzZXIvODg1Nw: {:title=>"ok"}

=> nil

My terminal and Rails server output

[ActionCable] [8857] Finished "/cable/" [WebSocket] for ::1 at 2017-09-13 11:38:00 +0200
[ActionCable] [8857] NotificationsChannel stopped streaming from notifications:Z2lkOi8vZ2FtZS1saWJyYXJ5L1VzZXIvODg1Nw
Started GET "/cable" for ::1 at 2017-09-13 11:38:00 +0200
Started GET "/cable/" [WebSocket] for ::1 at 2017-09-13 11:38:00 +0200
Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket)
User Load (0.7ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 8857], ["LIMIT", 1]]
[ActionCable] [8857] Registered connection (Z2lkOi8vZ2FtZS1saWJyYXJ5L1VzZXIvODg1Nw)
[ActionCable] [8857] NotificationsChannel is transmitting the subscription confirmation
[ActionCable] [8857] NotificationsChannel is streaming from notifications:Z2lkOi8vZ2FtZS1saWJyYXJ5L1VzZXIvODg1Nw

Here is my WebSocket installation:

channel/application_cable/connection.rb

 module ApplicationCable
   class Connection < ActionCable::Connection::Base
    identified_by :current_user

    def connect
      self.current_user = find_verified_user
      logger.add_tags 'ActionCable', current_user.id
    end

    protected

    def find_verified_user 
      if verified_user = env['warden'].user
        verified_user
      else
       reject_unauthorized_connection
      end
    end
  end
end

app/channels/notifications_channel.rb

class NotificationsChannel < ApplicationCable::Channel


  def subscribed
    stream_for current_user
  end

  def unsubscribed
    # Any cleanup needed when channel is unsubscribed
  end
end

app/assets/javascript/channels/notifications.coffee

App.cable.subscriptions.create channel: "NotificationsChannel",
  connected: ->
    console.log "connected"

  received: (data) ->
    console.log "ok"

I'm not seeing anything when I broadcast a message.

Answer №1

The issue has been identified as related to the Rails version.

To resolve this, simply upgrade from rails 5.0.1 to 5.0.2 if you are experiencing this problem.

Additionally, make sure to change 'async' in cable.yml to 'redis'.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Troubleshooting AJAX failures in Android Cordova app's Release mode

Encountering an issue with AJAX calls failing in release mode on Android but working fine on iOS. The error message seen in Chrome Dev Tools is: Provisional headers are shown Request URL:https://server.com/api/index.php?ticket=ST-111111-ABCDEFG-cas Requ ...

Help with developing a website focused on challenges centered around creating lists

I have a vision to create a unique website centered around list-based challenges. Drawing inspiration from the popular site , my goal is to allow users to explore various lists and mark off the options they have personally experienced, whether it's wa ...

Ways to periodically create random values and transmit them using MQTT protocol

I need help generating and publishing unique random values to the MQTT protocol every second. Currently, my code keeps sending the same value repeatedly instead of a different one each time. How can I fix this? var mqtt = require('mqtt') var Bro ...

What is the best way to make the current year the default selection in my Select control within Reactive Forms?

Hey there! I managed to create a select element that displays the current year, 5 years from the past, and 3 years from the future. But now I need to figure out how to make the current year the default selection using Reactive Forms. Any ideas on how to ac ...

Encountering a strange issue while attempting to convert a string to a date format using Angular

I am attempting to format a string into a Date. this.deadLine = new Date(this.deadLine); However, when I check the console, I receive an error message saying "Invalid Date". The output of this.deadLine without any specific format is: "2019-10-21T21:00: ...

Optimizing performance: Enhance readback operations in Canvas2D by enabling the willReadFrequently attribute for faster getImageData processing

I am currently utilizing the react-wordcloud package and encountering an issue where the word cloud adjusts to fit 70% of the screen size whenever the container size changes. My console is being flooded with this warning message: https://i.sstatic.net/vdV ...

Validate a string to determine if it is a legitimate numerical value using Javascript

How can we accurately determine if a string is a valid number in JavaScript? Although the method isNaN(str) is commonly used, it has limitations in certain cases, Current behavior: isNaN("1") = false, as it is a number, isNaN("1 ") = ...

Tips for Splitting Navigation Bar in HTML and CSS

I am facing an issue with my webpage's navigation bar, as I am unable to divide it into two parts - with some text on the left side and some on the right side. I attempted to use code from a specific reference: http://www.w3schools.com/css/css_navbar. ...

With the use of discreet JavaScript, the parameter is not empty; instead, it contains values

Previously, my JavaScript code was functioning correctly when it was within the same page as my cshtml file: function SaveEntity() { // more code here alert(entity.FirstName); /* this shows that entity's properties have values */ $.post( ...

Get rid of any type of encoding or default encoding that may be applied to a jQuery ajax call

Is it possible to completely remove all types of encoding, including default encoding, on a jQuery AJAX call? Here is an example JavaScript code: function callServer() { debugger; var uncompressed64Data = "/9j/4AAQSkZJRgABAQEAYABgAAD/2 ...

The parameter 'Value | ValueXY' cannot be assigned to the type 'AnimatedValue<0>'

Recently, I delved into React Native documentation on Animations which can be found here: https://reactnative.dev/docs/animated After reading the docs, I decided to try out some code snippets: import {Animated as RNAnimated} from 'react-native' ...

What are the best ways to maximize a web worker's ability to handle multiple tasks at once

I'm currently working on implementing a Web-Worker to handle its state while also managing multiple asynchronous requests. worker.ts file let a =0; //state of the worker let worker=self as unknown as Worker; worker.onmessage =(e)=>{ console ...

Build Your Own Alert Component in React Native

As I work on my react-native app, I am faced with the task of creating a custom alert method similar to Alert.alert() provided in the Official site of react-native. The default React-native alert lacks the ability to style properties such as Font Size an ...

How to Customize Columns in Kendo Grid, Populate with New Data, and Update?

I am working with a Kendo grid that has several columns. I want to be able to update the visibility of some columns, add new ones, and then display the updated data after a button click. Here is my attempt at achieving this: // GET THE EXISTING COLUMNS F ...

Imitate adjustment of orientation without the need to resize the browser window

Is there a way to simulate page portrait orientation on a PC browser without resizing the window? In my HTML code, I have a <div> element that displays content dynamically based on screen orientation. Is it possible to use JavaScript to trick this & ...

Having trouble retrieving the URL from JSON data - every time I attempt to access it, it just shows as undefined. Any suggestions

Having trouble extracting the URL from JSON, as it shows undefined. Any suggestions? <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" ></meta> <script language="JavaScript" type="text/javascript" ...

Issue: Unable to delete message due to message.$delete not being a valid function

Every time I attempt to execute a DELETE request using the angular-resource service, I consistently encounter the following message within the dev tools: Error: message.$delete is not a function $scope.deleteMessage@file:///Users/me/Desktop/angular/my ...

Is it possible to create two sticky headers with varying heights?

Looking to develop a website featuring two sticky elements at the top of the page - a sticky header and a sticky toolbar. Utilizing Bootstrap's Affix for the toolbar and sticky.js for the header. Encountering an issue where setting {topSpacing:0} cau ...

Is each series in Dygraphs stacked graph displayed separately?

I am looking to create a combined stacked graph and line graph, but I'm facing challenges as the stacked graph is not usable per-series. Can anyone provide guidance on how to achieve this? g = new Dygraph(document.getElementById("graph"), ...

Is there a way to extract Json from a Scala Json string and store it in a JS variable?

Currently, I am utilizing the Play framework and attempting to transmit a Json string from the server as a parameter to a Scala template. @(aj: String) @import play.api.libs.json.Json <!DOCTYPE html> <html lang="en"> <body> < ...