DEV Community

Cover image for Add Bootstrap 4 to your Ruby on Rails 6 application
Somnath.geek
Somnath.geek

Posted on

11 4

Add Bootstrap 4 to your Ruby on Rails 6 application

Step 1: Using Yarn:

yarn add bootstrap@4.3.1 jquery popper.js

package.json file should look like this

"dependencies": {
    "@rails/actioncable": "^6.0.0",
    "@rails/activestorage": "^6.0.0",
    "@rails/ujs": "^6.0.0",
    "@rails/webpacker": "4.2.2",
    "bootstrap": "4.3.1",
    "jquery": "^3.4.1",
    "popper.js": "^1.16.1",
    "turbolinks": "^5.2.0"
  },

Step 2: Head to config/webpack/environment.js file and add these lines

const { environment } = require('@rails/webpacker')

const { environment } = require('@rails/webpacker')

const webpack = require("webpack")

environment.plugins.append("Provide", new webpack.ProvidePlugin({

$: 'jquery',

jQuery: 'jquery',

Popper: ['popper.js', 'default']

}))

module.exports = environment

Step 3 : Head to app/assets/stylesheets/application.css and add these lines

*= require bootstrap

*= require_tree .

*= require_self

Congratulation! You have successfully installed Bootstrap 4 πŸ˜€

Top comments (3)

Collapse
 
natarajan1993 profile image

Just a little addition to the steps. You also need to add

import "bootstrap"

to app/javascript/packs/application.js

Collapse
 
sevicode profile image
Sevicode β€’

The last part result in an error. You sure is the format correct?

Collapse
 
arosenfeld2003 profile image
Alex Rosenfeld β€’

The top of app/assets/stylesheets/application.css should look like this:

/*
  *= require bootstrap
  *= require_tree .
  *= require_self
*/

Jetbrains image

Build Secure, Ship Fast

Discover best practices to secure CI/CD without slowing down your pipeline.

Read more

πŸ‘‹ Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay