Sha256: 794b6548f53fb001825eeff41b4d55f7e15276dea77e0b84b7bade649a42cf8d

Contents?: true

Size: 1.57 KB

Versions: 56

Compression:

Stored size: 1.57 KB

Contents

# frozen_string_literal: true

module ActionCable
  module Helpers
    module ActionCableHelper
      # 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-turbo-track' => 'reload' %>
      #   </head>
      #
      # This is then used by Action Cable to determine the URL of your WebSocket server.
      # Your JavaScript can then connect to the server without needing to specify the
      # URL directly:
      #
      #   import Cable from "@rails/actioncable"
      #   window.Cable = Cable
      #   window.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" />
      #
      def action_cable_meta_tag
        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")
        )
      end
    end
  end
end

Version data entries

56 entries across 53 versions & 6 rubygems

Version Path
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/actioncable-7.1.3.4/lib/action_cable/helpers/action_cable_helper.rb
actioncable-7.1.5.1 lib/action_cable/helpers/action_cable_helper.rb
actioncable-7.0.8.7 lib/action_cable/helpers/action_cable_helper.rb
actioncable-7.1.5 lib/action_cable/helpers/action_cable_helper.rb
actioncable-7.1.4.2 lib/action_cable/helpers/action_cable_helper.rb
actioncable-7.0.8.6 lib/action_cable/helpers/action_cable_helper.rb
actioncable-7.1.4.1 lib/action_cable/helpers/action_cable_helper.rb
actioncable-7.0.8.5 lib/action_cable/helpers/action_cable_helper.rb
actioncable-7.1.4 lib/action_cable/helpers/action_cable_helper.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/actioncable-7.0.8.4/lib/action_cable/helpers/action_cable_helper.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/actioncable-7.1.3.4/lib/action_cable/helpers/action_cable_helper.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/actioncable-7.0.5.1/lib/action_cable/helpers/action_cable_helper.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/actioncable-7.0.5.1/lib/action_cable/helpers/action_cable_helper.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/actioncable-7.0.5.1/lib/action_cable/helpers/action_cable_helper.rb
tinymce-rails-7.1.2 vendor/bundle/ruby/3.3.0/gems/actioncable-7.1.3.4/lib/action_cable/helpers/action_cable_helper.rb
actioncable-7.1.3.4 lib/action_cable/helpers/action_cable_helper.rb
actioncable-7.0.8.4 lib/action_cable/helpers/action_cable_helper.rb
actioncable-7.1.3.2 lib/action_cable/helpers/action_cable_helper.rb
actioncable-7.1.3.1 lib/action_cable/helpers/action_cable_helper.rb
actioncable-7.0.8.1 lib/action_cable/helpers/action_cable_helper.rb