OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Issue with setting up actioncable

  • Thread starter Thread starter Aadhi
  • Start date Start date
A

Aadhi

Guest
My project is set up as rails only API application, and flagged with no javascript. they have added active admin to it and made necessary changes to it making javascripts folder in assets as required by active admin. now i need to add actioncable functionality along with chat for it. for user side it is fine as we are using react front-end. but for admin i need to implement actioncable to push messages in real time to browser. how can i set it up. I have even tried with importmap-rails. ruby- 2.6.5 rails -6.0.6.1

my approach was I tried to create a chat_channel.js in app/assests/javascripts/channels and added following snipped and added a javascript_include_tag as module in required page-view from admin

Code:
import consumer from "./consumer"

consumer.subscriptions.create("ChatChannel", {
  connected() {
    console.log("Connected to the chat channel.");
  },

  disconnected() {
    console.log("Disconnected from the chat channel.");
  },

  received(data) {
    console.log("Received message:", data.message);
    // Handle the received message here
  }
});

my consumer.js file has

Code:
import { createConsumer } from "@rails/actioncable"

const consumer = createConsumer()

export default consumer

error i am facing when it is loaded load_messages:1 Uncaught TypeError: Failed to resolve module specifier "@rails/actioncable". Relative references must start with either "/", "./", or "../".

there is no package.json file at the starting, but as tried to do so with npm install and add actioncable. but none of them worked.

i got it i am unable to load modules properly. i tried npm i @rails/actioncable, or yarn add @rails/actioncable. those things didnt help. i tried with impotmaps-rails following this guide. as this has similarities with my case.this also ended with same error.

<p>My project is set up as rails only API application, and flagged with no javascript. they have added active admin to it and made necessary changes to it making javascripts folder in assets as required by active admin. now i need to add actioncable functionality along with chat for it. for user side it is fine as we are using react front-end. but for admin i need to implement actioncable to push messages in real time to browser. how can i set it up. I have even tried with importmap-rails.
ruby- 2.6.5
rails -6.0.6.1</p>
<p>my approach was I tried to create a chat_channel.js in app/assests/javascripts/channels and added following snipped and added a javascript_include_tag as module in required page-view from admin</p>
<pre><code>import consumer from "./consumer"

consumer.subscriptions.create("ChatChannel", {
connected() {
console.log("Connected to the chat channel.");
},

disconnected() {
console.log("Disconnected from the chat channel.");
},

received(data) {
console.log("Received message:", data.message);
// Handle the received message here
}
});

</code></pre>
<p>my consumer.js file has</p>
<pre><code>import { createConsumer } from "@rails/actioncable"

const consumer = createConsumer()

export default consumer

</code></pre>
<p>error i am facing when it is loaded
<code>load_messages:1 Uncaught TypeError: Failed to resolve module specifier "@rails/actioncable". Relative references must start with either "/", "./", or "../".</code></p>
<p>there is no package.json file at the starting, but as tried to do so with npm install and add actioncable. but none of them worked.</p>
<p>i got it i am unable to load modules properly. i tried npm i @rails/actioncable, or yarn add @rails/actioncable. those things didnt help. i tried with impotmaps-rails following <a href="https://stackoverflow.com/questions...able-with-importmaps-in-rails-6-mri-and-jruby">this guide</a>. as this has similarities with my case.this also ended with same error.</p>
 
Top