0

I'm currently following the official Rails ActionCable guide.

It suggests creating a file for the subscriptions (App.cable.subscriptions.create{...}) in app/assets/javascripts/cable/subscriptions/channelname.coffee - but when I use the command rails g channel channelname methodname it creates the corresponding file in app/assets/javascripts/channels/channelname.coffee

I've also been following this guide at nopio, that says it should be a JavaScript file - app/assets/javascripts/channels/channelname.js

I'm using Ruby 2.3.3 and Rails 5.0.2. Which place and which filetype is correct? Thanks for your help! :)

megahra
  • 295
  • 2
  • 19

1 Answers1

0

It is only one-two string of code. Why to use for that special file. I use react and just place it in my notification component:

class Notifications extends React.Component {
  constructor(props) {
    super(props);
    this.subscribeNofications()
  }

  subscribeNofications = () => {
    this._notificationChannel = App.cable.subscriptions.create(
      { channel: "NotificationsChannel", room: this.getUserChannel() }, {
      received: this.showNotification
    })
  }

  showNofication = (data) => {
    alert(data.message)
  }
}

So place it as general code according to your application.

fl-web
  • 462
  • 5
  • 16