Skip to content
Advertisement

Bootstrap 5 Javascript Functions not Working in Rails 7 app

I’m trying to set up my first Rails 7 app and have installed Bootstrap 5 properly (you can see by the CSS) and gotten rid of all the error messages, but the javascript functions (i.e. dropdown menus, offcanvas, etc.) aren’t working.

I have tested it with this code:

JavaScript

And both console.log statments produce the correct result, leading me to believe js and jquery are working properly and it is something with bootstrap.

Here’s my gemfile:

JavaScript

Here’s my application.js, which lives in ‘javascript/controllers/application.js but somehow also inassets/builds/application.js. I'm not using webpack, rather rollup installed with $ ./bin/rails javascript:install:rollup`:

JavaScript

Can anyone see where I’m going wrong?

Advertisement

Answer

I had the same problem.

I got things working by adding the bundle script from Bootstrap in the between the body tags of the application.html.erb file:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement