瀏覽代碼

Add Javascript templates for webpacker

Chris Oliver 5 年之前
父節點
當前提交
e74e4a9ee2
共有 3 個文件被更改,包括 31 次插入0 次删除
  1. 6 0
      app/javascript/channels/consumer.js
  2. 5 0
      app/javascript/channels/index.js
  3. 20 0
      app/javascript/packs/application.js

+ 6 - 0
app/javascript/channels/consumer.js

@@ -0,0 +1,6 @@
+// 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.
+
+import { createConsumer } from "@rails/actioncable"
+
+export default createConsumer()

+ 5 - 0
app/javascript/channels/index.js

@@ -0,0 +1,5 @@
+// Load all the channels within this directory and all subdirectories.
+// Channel files must be named *_channel.js.
+
+const channels = require.context('.', true, /_channel\.js$/)
+channels.keys().forEach(channels)

+ 20 - 0
app/javascript/packs/application.js

@@ -0,0 +1,20 @@
+// This file is automatically compiled by Webpack, along with any other files
+// present in this directory. You're encouraged to place your actual application logic in
+// a relevant structure within app/javascript and only use these pack files to reference
+// that code so it'll be compiled.
+
+require("@rails/ujs").start()
+require("turbolinks").start()
+require("@rails/activestorage").start()
+require("channels")
+require("local-time").start()
+
+window.Rails = Rails
+
+import 'bootstrap'
+import 'data-confirm-modal'
+
+$(document).on("turbolinks:load", () => {
+  $('[data-toggle="tooltip"]').tooltip()
+  $('[data-toggle="popover"]').popover()
+})