$ is not defined when installing jQuery in Rails via Webpack

后端 未结 5 1597
猫巷女王i
猫巷女王i 2021-02-18 19:04

I\'m trying to install jQuery in Rails 6.0.0.rc1 via Webpack and I\'m not sure what I\'m missing but I\'m getting the error $ is not defined in the browser console

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-18 19:31

    I've got what's missing.

    In app/javascript/packs/application.js forgot to declare:

    window.jQuery = $;
    window.$ = $;
    

    So jQuery keywords could be picked up.

提交回复
热议问题