2015-09-03 20:17:48 -04:00
|
|
|
module ActionCable
|
|
|
|
module Helpers
|
|
|
|
module ActionCableHelper
|
2016-02-27 13:53:31 -05:00
|
|
|
# Returns an "action-cable-url" meta tag with the value of the URL specified in your
|
|
|
|
# configuration. Ensure this is above your JavaScript tag:
|
2015-09-03 20:17:48 -04:00
|
|
|
#
|
|
|
|
# <head>
|
|
|
|
# <%= action_cable_meta_tag %>
|
|
|
|
# <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
|
|
|
|
# </head>
|
|
|
|
#
|
2016-02-27 13:53:31 -05:00
|
|
|
# This is then used by Action Cable to determine the URL of your WebSocket server.
|
2015-09-03 20:17:48 -04:00
|
|
|
# Your CoffeeScript can then connect to the server without needing to specify the
|
2016-02-27 13:53:31 -05:00
|
|
|
# URL directly:
|
2015-09-03 20:17:48 -04:00
|
|
|
#
|
|
|
|
# #= require cable
|
|
|
|
# @App = {}
|
|
|
|
# App.cable = Cable.createConsumer()
|
|
|
|
#
|
2016-02-27 13:53:31 -05:00
|
|
|
# Make sure to specify the correct server location in each of your environment
|
|
|
|
# config files:
|
2015-09-03 20:17:48 -04:00
|
|
|
#
|
2016-02-04 22:33:46 -05:00
|
|
|
# config.action_cable.mount_path = "/cable123"
|
|
|
|
# <%= action_cable_meta_tag %> would render:
|
|
|
|
# => <meta name="action-cable-url" content="/cable123" />
|
|
|
|
#
|
|
|
|
# config.action_cable.url = "ws://actioncable.com"
|
|
|
|
# <%= action_cable_meta_tag %> would render:
|
|
|
|
# => <meta name="action-cable-url" content="ws://actioncable.com" />
|
|
|
|
#
|
2015-09-03 20:17:48 -04:00
|
|
|
def action_cable_meta_tag
|
2016-02-04 22:33:46 -05:00
|
|
|
tag "meta", name: "action-cable-url", content: (
|
|
|
|
ActionCable.server.config.url ||
|
|
|
|
ActionCable.server.config.mount_path ||
|
|
|
|
raise("No Action Cable URL configured -- please configure this at config.action_cable.url")
|
|
|
|
)
|
2015-09-03 20:17:48 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|