I am trying to follow an action cable tutorial that I believe was done on an older version of rails. They used the function below in CoffeeScript. However, when I try to run it, the console prints out the error appended to the code block of the respective attempts. The first block is the tutorial, the second block is me trying to work around the problem.
The thing is that the tutorial doesn't explicitly explain the purpose of APP or what it represents.
(function() {
this.App || (this.App = {});
App.cable = ActionCable.createConsumer();
}).call(this);
Error:
CoffeeScriptError: C:\Users\User\Documents\Projects\ror\ror-portfolio-1-dev-match-master\app\javascript\packs\application_coffee.coffee:23:2: error: reserved word 'function'
(function() {
cableFunc {
this.App || (this.App = {});
App.cable = ActionCable.createConsumer();
}
cableFunc()
Error:
CoffeeScriptError: C:\Users\User\Documents\Projects\ror\ror-portfolio-1-dev-match-master\app\javascript\packs\application_coffee.coffee:24:2: error: unexpected this
this.App || (this.App = {});
If someone could tell me why this isn't compiling, cause as far as it goes the CoffeScript should not be throwing the error it is throwing, I would be grateful.
Also, I used webpacker:install:coffee to setup CoffeeScript in my application.
https://www.sitepoint.com/rails-and-actioncable-adding-advanced-features/I believe it is an old one.