###実現したいこと・前提
raty.jsを使った評価機能の実装
(環境)
・ruby 2.6.5
・Rails 6.0.0
Rails6にはassets/javascriptsがないので作成しました
assets/javascripts/jquery.raty.jsを作成しリンク内容をコピーで貼っています
###発生している問題
jquery.raty.jsで評価機能を実装したいが、jsが効いていない。
###発生しているエラー文
Uncaught TypeError: $(...).raty is not a function
###該当のソースコード
books/new.html.erb
erb
1<div class="form-group row" id="star"> 2 <%= f.label :star,'評価 ', class:'col-md-3 col-form-label' %> 3 <%= f.hidden_field :star, id: :review_star %> 4 </div> 5 <script> 6 $('#star').raty({ 7 size : 36, 8 starOff: '<%= asset_path('star-off.png') %>', 9 starOn : '<%= asset_path('star-on.png') %>', 10 starHalf: '<%= asset_path('star-half.png') %>', 11 scoreName: 'book[star]', 12 half: true 13 }); 14 </script> 15
app/javascript/packs/application.js
erb
1// This file is automatically compiled by Webpack, along with any other files 2// present in this directory. You're encouraged to place your actual application logic in 3// a relevant structure within app/javascript and only use these pack files to reference 4// that code so it'll be compiled. 5 6require("@rails/ujs").start() 7//require("turbolinks").start() 8require("@rails/activestorage").start() 9require("channels") 10require('jquery') 11//=require jquery.raty.js 12 13 14// Uncomment to copy all static images under ../images to the output folder and reference 15// them with the image_pack_tag helper in views (e.g <%= image_pack_tag 'rails.png' %>) 16// or the `imagePath` JavaScript helper below. 17// 18// const images = require.context('../images', true) 19// const imagePath = (name) => images(name, true)
###試したこと
いろいろな記事を試してみましたが環境が違ったりとで、うまくいきませんでした。
よろしくお願いします
あなたの回答
tips
プレビュー