Uncaught ReferenceError: $ is not defined rails

前端 未结 7 2095
后悔当初
后悔当初 2021-01-11 11:08

I\'m trying to add Froala editor to my project.

Problem only on production server(on localhost it works fine) I\'m using rails 4.1.0 In gemfile i\'m have

<         


        
相关标签:
7条回答
  • 2021-01-11 11:40

    The following is what I needed to do for Rails 6 (6.0.3.4 to be exact.) [found at (all credit goes to): https://www.botreetechnologies.com/blog/introducing-jquery-in-rails-6-using-webpacker]

    1. Add jQuery to environment. $ yarn add jquery

    2. Add below code in environment.js (<app_path>/config/webpack/environment.js)

       const webpack = require('webpack')
       environment.plugins.prepend('Provide',
       new webpack.ProvidePlugin({
           $: 'jquery/src/jquery',
           jQuery: 'jquery/src/jquery'
       })
       )
      
    3. Require jquery in application.js file. (/app/javascript/packs/application.js) require('jquery')

    4. (Restart rails server to make sure everything gets loaded.)

    0 讨论(0)
提交回复
热议问题