Home How to install Bootstrap and jQuery in Rails 7 app with importmap
Post
Cancel

How to install Bootstrap and jQuery in Rails 7 app with importmap

First, add to your Gemfile

1
2
3
gem 'jquery-rails'
gem 'bootstrap'
gem 'sassc-rails'

And run bundle install

Rename app/assets/stylesheets/application.css to app/assets/stylesheets/application.scss

Then, add to application.scss above

1
@import "bootstrap";

Add to config/importmap.rb

1
2
3
4
pin "jquery", to: "jquery.min.js", preload: true
pin "jquery_ujs", to: "jquery_ujs.js", preload: true
pin "popper", to: "popper.js", preload: true
pin "bootstrap", to: "bootstrap.min.js", preload: true

Add to app/javascript/application.js

1
2
3
4
import "jquery"
import "jquery_ujs"
import "popper"
import "bootstrap"

Add to assets/config/manifest.js

1
2
3
4
//= link jquery.min.js
//= link jquery_ujs.js
//= link popper.js
//= link bootstrap.min.js

This is all you need to have Bootstrap and jQuery fully working


I also created a video to show it. You can check it out on Youtube here:


This post is licensed under CC BY 4.0 by the author.