I'm finally getting around to using Rails 6 (hooray for legacy projects!) and learning about some of the differences. One of those, I encountered was how to add jQuery to our application.
Most of our legacy projects include the
From the root of your Rails directory run:
You should now see jquery listed in your
package.json file. Awesome! Now let's add it to
Just one last thing we need to do to be able to use jQuery, though. In your
/config/webpack/environment.js file add:
This should go just before the line that exports the environment. Think of this file as similar to your Rails
/config/environment.rb, in that it contains the common JS stuff across all environments. You may notice that there are per environment JS files (development.js, production.js, test.js) there as well to allow you to specify JS per environment.
You should be all set to use jQuery in your Rails app now. If I missed anything, let me know in the comments!
Need web application development, maintenance for your existing app, or a third party code review?
Velocity Labs can help.Hire us!