Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def create
- # Create action logic here
- if @story.save
- NotifyNewStoryJob.perform_later @story
- else
- # Error handling
- end
- end
- class NotifyNewStoryJob < ApplicationJob
- queue_as :default
- def perform(story)
- ActionCable.server.broadcast "stories_channel", story
- end
- end
- class StoriesChannel < ApplicationCable::Channel
- def subscribed(data)
- stream_from "stories_channel"
- end
- def unsubscribed
- # Any cleanup needed when channel is unsubscribed
- end
- end
- App.stories = App.cable.subscriptions.create("StoriesChannel", {
- connected: function() {
- // Called when the subscription is ready for use on the server
- },
- disconnected: function() {
- // Called when the subscription has been terminated by the server
- },
- received: function(data) {
- console.log(data); // Just for debugging purposes
- }
- });
- $ docker-compose exec website -u 1000 rails db:create db:migrate
- $ docker-compose g job NotifyNewStoryJob
- $ docker-compose g channel Stories
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement