I'm currently trying to implement a datepicker into my application, the problem is that there is no documentation on how to add the jquery-ui-rails
gem through webpacker.
Probably there is another way to add gems or another gem that would fit my needs?
Kalman's answer puts jQuery within the scope of the scripts in the
app/javascript
directory but not with any in-line javascript that you may have on your webpages.If you want to access jQuery from the scope of the webpage, you could can put jQuery under the
public
directory then modifyapp/views/layouts/application.html.erb
to link to it like this:None of these answers quite worked for me. Here's how I ended up getting it implemented:
then
in your app/javascript/packs/application.js file:
and in config/webpack/environment.js:
A restart to my server got it working fine for me. Here is a link with details on webpacker that I used to get this to work:
https://gist.github.com/maxivak/2612fa987b9f9ed7cb53a88fcba247b3#jquery-jquery-ui
You no longer need to add javascript libraries as gems (which are managed by the bundler). Instead, you add them with yarn and they are managed by webpack (which is enabled by adding the webpacker gem to the Gemfile).
The following steps worked for me to get jquery-ui working in Rails 6:
config/webpack/environment.js
needs to look as follows:Restart your rails server
In the
application.html.erb
, include thejquery-ui
theme:app/javascript/packs/application.js
, you can usejquery-ui
:This will work for a page that looks as follows: