method
action_cable_meta_tag
v6.0.0 -
Show latest stable
-
0 notes -
Class: ActionCableHelper
- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3
- 2.1.0
- 2.2.1
- 2.3.8
- 3.0.0
- 3.0.9
- 3.1.0
- 3.2.1
- 3.2.8
- 3.2.13
- 4.0.2
- 4.1.8
- 4.2.1
- 4.2.7
- 4.2.9
- 5.0.0.1 (0)
- 5.1.7 (5)
- 5.2.3 (0)
- 6.0.0 (0)
- 6.1.3.1 (38)
- 6.1.7.7 (0)
- 7.0.0 (14)
- 7.1.3.2 (0)
- What's this?
action_cable_meta_tag()
public
Returns an “action-cable-url” meta tag with the value of the URL specified in your configuration. Ensure this is above your JavaScript tag:
<head> <%= action_cable_meta_tag %> <%= javascript_include_tag 'application', 'data-turbolinks-track' => 'reload' %> </head>
This is then used by Action Cable to determine the URL of your WebSocket server. Your CoffeeScript can then connect to the server without needing to specify the URL directly:
#= require cable @App = {} App.cable = Cable.createConsumer()
Make sure to specify the correct server location in each of your environment config files:
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" />