1

cable_ready 4.5.0 rails 6.1.4.1 ruby 3.0.2p107

This is a simple example from the basic tutorial (https://www.youtube.com/watch?v=F5hA79vKE_E) I suspect the error I am getting is because either cable_ready or rails evolved a little and created a tiny incompatibility.

I get this error in the JS console:

enter image description here

It is triggered when in my controller I ask cable ready to:

cable_ready["timeline"].console_log(message: "***** cable ready post created")

Which leads to my timeline_channel to:

received(data) {
    console.log("******** Received data:", data.operations)
    if (data.cableReady) CableReady.perform(data.operations)
  }

My interpretation is perform causes this line in cable_ready.js line 13:

  operations.forEach(function (operation) {
    if (!!operation.batch) batches[operation.batch] = batches[operation.batch] ? ++batches[operation.batch] : 1;
  });

Is finding something in the received data that it doesn't like.

That's where my trail ends. Can someone see what I am doing wrong, or tell me what other code you'd like me to include?

pitosalas
  • 10,286
  • 12
  • 72
  • 120

1 Answers1

1

Solution: downgrade the version of the cable_ready javascript library.

I previously (maybe a year ago) did this tutorial using CableReady 4.5, Ruby 2.6.5 and Rails 6.0.4 and it worked like a charm back then as well as today.

But today, I tried this tutorial again on a duplicate project--same versions of CR, Ruby, and Rails and now I get java console errors similar to yours.

TypeError: undefined is not a function (near '...operations.forEach...')
perform -- cable_ready.js:13
received -- progress_bar_channel.js:8

I looked at the output of yarn list and saw that cable_ready was version 5.0.0-pre8 on the bad project and it was 5.0.0-pre1 on the good project. The downgrade could be accomplished with yarn add cable_ready@^5.0.0-pre1 in the bad project folder and now both projects work.

FYI for other newbies like me trying to understand how CableReady works: This tutorial gives another example of CableReady, and was also fixed the same way.

Eli R.
  • 188
  • 11