I'm a little addicted, so make a note
JQuery $ ('# hoge')
didn't work when I called js.erb on a controller that received the remote: true
form of a Rails 6 view.
JS error occurred: ʻUncaught ReferenceError: $ is not defined`
Add the following line in app / javascript / packs / application.js
app/javascript/packs/application.js
...
require("bootstrap")
require("admin-lte")
window.$ = jQuery; //here!
js:hogehoge.js.erb
$('.modal_area').html('<%= j(render "modal") %>');
$('#modal').modal('show');
I had a similar definition in config / webpack / environment.js, but I needed this description to use it from within the js.erb file.
Recommended Posts