Webpacker
とyarn
とslim
を利用。
普通にやるとこんな感じでエラーがでる。
Templates should only be responsible for mapping the state to the UI. Avoid placing tags with side-effects in your templates, such as <script>, as they will not be parsed.
vue-script2
を使うと簡単にできる。
-
vue-script2
をインストール
yarn add vue-script2
-
javascript/packs
下にjs
ファイルを置く
javascript/packs/hello.js
console.log("hello")
-
<script2>
タグを使って呼び出し
layout/application.html.slim
- path = asset_pack_path 'hello.js'
script2 src="#{path}"