diff options
-rw-r--r-- | actioncable/app/assets/javascripts/action_cable/connection.coffee | 4 | ||||
-rw-r--r-- | railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/cable.coffee | 8 |
2 files changed, 6 insertions, 6 deletions
diff --git a/actioncable/app/assets/javascripts/action_cable/connection.coffee b/actioncable/app/assets/javascripts/action_cable/connection.coffee index ee888f567b..4244322a1e 100644 --- a/actioncable/app/assets/javascripts/action_cable/connection.coffee +++ b/actioncable/app/assets/javascripts/action_cable/connection.coffee @@ -6,9 +6,11 @@ class ActionCable.Connection @reopenDelay: 500 constructor: (@consumer) -> - @open() send: (data) -> + unless @isOpen() + @open() + if @isOpen() @webSocket.send(JSON.stringify(data)) true diff --git a/railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/cable.coffee b/railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/cable.coffee index 07934d026f..af08f58e34 100644 --- a/railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/cable.coffee +++ b/railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/cable.coffee @@ -1,11 +1,9 @@ # Action Cable provides the framework to deal with WebSockets in Rails. # You can generate new channels where WebSocket features live using the rails generate channel command. # -# Turn on the cable connection by removing the comments after the require statements (and ensure it's also on in config/routes.rb). -# #= require action_cable #= require_self #= require_tree ./channels -# -# @App ||= {} -# App.cable = ActionCable.createConsumer() + +@App ||= {} +App.cable = ActionCable.createConsumer() |