What is the proper way to upgrade Bootstrap 4 for Rails?

1.4k Views Asked by At

I tried to upgrade from Bootstrap 4 Alpha 6 to 4.0.0 final version for my Rails 5 project, I'm sure the v4.0.0 gem has been installed (I also uninstalled the alpha version gem), but when I run my project (dev mode), I found the generated Bootstrap CSS files are still based on the Alpha version.

gem 'bootstrap', '~> 4.0.0'

Other than uninstalling the old gem and install the new bootstrap gem, do I need to do anything else for the upgrade? Download the physical v4.0.0 files and replace the old files in my project?

2

There are 2 best solutions below

0
Vishal Taj PM On

You can have look at this article:

How to update a single gem conservatively

Option 1

This will work if all dependencies for the update are already satisfied.

  1. Find out the version you want to update to

  2. Change it directly in Gemfile.lock

  3. Run bundle install and see if that worked

Option 2

This will work if the gem has no shared dependencies with other gems.

  1. Find out the version you want to update to.
  2. Add that version explicitly to the Gemfile with , '=1.2.3'
  3. Run bundle install
  4. Remove the explicit version number again
  5. Run bundle install once more

Option 3

This should always work.

  1. Run bundle update GEMNAME
  2. Run git diff Gemfile.lock and notice all the updates you didn't want
  3. Revert the unwanted changes to Gemfile.lock you don't want (manually or by staging changed lines one-by-one), leaving only the desired updates.
  4. Run bundle install and see if that worked

Option 4

There are persistent rumors that you can update a single gem by calling bundle update --source GEMNAME. However no one seems to know how and why this works, it's not a documented feature of Bundler. It might be an unintended side effect of something else.

I believe this command will try to update GEMNAME and GEMNAME only. If this leads to unmatched dependencies to other locked gems, it will fail.

If you use this option, be sure to git diff your Gemfile.lock to see if the changes are what you expected.

Option 5

Bundler >= 1.14 has a --conservative flag. Using the conservative flag allows bundle update GEM to update the version of GEM, but prevents Bundler from updating the versions of any of the gems that GEM depends on.

Credits To Author: Henning Koch

0
gdurelle On

Try to keep Ruby dependencies in your Gemfile and JS/CSS ones elsewhere. Node+Yarn is a good way to do that.

If not already there

brew install yarn

Then in config/initializers/assets.rb

Rails.application.config.assets.paths << Rails.root.join('node_modules')

Now you can do this in your console:

yarn add bootstrap

It should have create a node-modules directory if not already there. Then just add bootstrap to your JS/SCSS files

JS

//= require bootstrap/js/src/index

CSS

@import "bootstrap/scss/bootstrap";