Advertisement
Guest User

Untitled

a guest
Aug 19th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. def create
  2. # Create action logic here
  3. if @story.save
  4. NotifyNewStoryJob.perform_later @story
  5. else
  6. # Error handling
  7. end
  8. end
  9.  
  10. class NotifyNewStoryJob < ApplicationJob
  11. queue_as :default
  12.  
  13. def perform(story)
  14. ActionCable.server.broadcast "stories_channel", story
  15. end
  16. end
  17.  
  18. class StoriesChannel < ApplicationCable::Channel
  19. def subscribed(data)
  20. stream_from "stories_channel"
  21. end
  22.  
  23. def unsubscribed
  24. # Any cleanup needed when channel is unsubscribed
  25. end
  26. end
  27.  
  28. App.stories = App.cable.subscriptions.create("StoriesChannel", {
  29. connected: function() {
  30. // Called when the subscription is ready for use on the server
  31. },
  32.  
  33. disconnected: function() {
  34. // Called when the subscription has been terminated by the server
  35. },
  36.  
  37. received: function(data) {
  38. console.log(data); // Just for debugging purposes
  39. }
  40. });
  41.  
  42. $ docker-compose exec website -u 1000 rails db:create db:migrate
  43. $ docker-compose g job NotifyNewStoryJob
  44. $ docker-compose g channel Stories
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement