環境
ruby 3.1.2
rails 6.1.4
raty 4.1.0
実現したいこと
・ratyを使い、本の投稿時にレビューをできるようにしたい
発生している問題・エラーメッセージ
books:109 Uncaught TypeError: $(...).raty is not a function at books:109:16
該当のソースコード
_form.html.erb
1<%= form_with model:book,local:true do |f| %> 2 <div id="error_explanation"> 3 <% if book.errors.any? %> 4 <h3><%= book.errors.count %>errors prohibited this obj from being saved:</h3> 5 <ul> 6 <% book.errors.full_messages.each do |message| %> 7 <li><%= message %></li> 8 <% end %> 9 </ul> 10 <% end %> 11 </div> 12 <div class="form-group"> 13 <%= f.label :title %> 14 <%= f.text_field :title, class: 'form-control book_title' %> 15 </div> 16 <div class="form-group"> 17 <%= f.label :opinion %> 18 <%= f.text_area :body, class: 'form-control book_body' %> 19 </div> 20 <div class="form-group row" id="star"> 21 <%= f.label :star,'評価 ', class:'col-md-3 col-form-label' %> 22 <%= f.hidden_field :star, id: :review_star %> 23 </div> 24 <script> 25 $('#star').empty(); 26 $('#star').raty({ 27 size : 36, 28 starOff: '<%= asset_path('star-off.png') %>', 29 starOn : '<%= asset_path('star-on.png') %>', 30 scoreName: 'book[star]', 31 half: false, 32 }); 33 </script> 34 <div class="form-group"> 35 <%= f.submit class: 'btn btn-success' %> 36 </div> 37<% end %>
application.js
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 6import Rails from "@rails/ujs" 7import Turbolinks from "turbolinks" 8import * as ActiveStorage from "@rails/activestorage" 9import "channels" 10import "jquery" 11import "popper.js" 12import "bootstrap" 13import '@fortawesome/fontawesome-free/js/all'; 14import "../stylesheets/application" 15window.$ = window.jQuery = require('jquery'); 16require('packs/raty') 17 18Rails.start() 19Turbolinks.start() 20ActiveStorage.start()
enviroment.js
1const { environment } = require('@rails/webpacker') 2 3const webpack = require('webpack') 4environment.plugins.prepend( 5 'Provide', 6 new webpack.ProvidePlugin({ 7 $: 'jquery/src/jquery', 8 jQuery: 'jquery/src/jquery', 9 Popper: 'popper.js' 10 }) 11) 12module.exports = environment
試したこと
yarn add jgueryをもう一度行ったりしましたが全く変わりませんでした。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。