Skip to content

Instantly share code, notes, and snippets.

@kryptykphysh
Last active June 25, 2025 14:55
Show Gist options
  • Save kryptykphysh/2aef769205d3599ad3c3d314c2f190b1 to your computer and use it in GitHub Desktop.
Save kryptykphysh/2aef769205d3599ad3c3d314c2f190b1 to your computer and use it in GitHub Desktop.
simple chat
{{input value=username}}
{{input value=body}}
<button {{action 'sendMessage'}} data-turbo="false">
Send
</button>
{{#each messages as |message|}}
<p>{{message.username}} -> {{message.body}}</p>
{{/each}}
import Ember from 'ember';
import ActionCable from "actioncable";
export default Ember.Component.extend({
setupSubscription: Ember.on('init', function () {
const consumer = ActionCable.createConsumer("ws://app.rails.localhost:3000/cable");
console.log(consumer);
const subscription = consumer.subscriptions.create({
channel: 'MessageChannel',
room: 'messages'
}, {
received: (data) => {
console.log(data);
this.get('messages').pushObject({
username: data.username,
body: data.body,
});
},
});
this.set('subscription', subscription);
}),
actions: {
sendMessage() {
this.get('subscription').send({
username: this.get('username'),
body: this.get('body'),
});
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment