3
votes

I have tried every tutorial and every guide but I am not able to integrate bootstrap in my rails app I have tried bootstrap-sass gem, bootstrap CDN, bootstrap gem

Ruby on Rails version 5.2.0 Ruby version 2.2.6

EXACTLY FOLLOWED THESE TUTORIALS AND HAVE ACHIEVED 0 RESULTS:

for bootstrap sass https://github.com/twbs/bootstrap-sass

for bootstrap https://github.com/twbs/bootstrap

tried using bootstrap CDN https://www.bootstrapcdn.com/

I have been stuck on this for weeks, tried solving it on my own, followed many blog posts and StackOverflow answers and tried everything. Is it a problem with rails 5.2 version? or my operating system windows 10 is there a gem missing in my gem file?

EDIT: I can run bundle install successfully, adding CDN in my head tag in application.html.erb does not solve my problem The problem I am facing is that I cant use bootstrap no matter what method I try

GEM FILE :

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.2.6'


gem 'rails', '~> 5.2.0'


gem 'sqlite3'


gem 'puma', '~> 3.11'


gem 'coffee-script-source', '1.8.0'


gem 'bootstrap-sass', '~> 3.3.7'


gem 'sass-rails', '~> 5.0'


gem 'jquery-rails'


gem 'uglifier', '>= 1.3.0'


gem 'duktape'


gem 'coffee-rails', '~> 4.2'


gem 'turbolinks', '~> 5'


gem 'jbuilder', '~> 2.5'


gem 'bootsnap', '>= 1.1.0', require: false
3
Can you successfully bundle install? - Sara Fuerst
Try to add cdn link in head section of application.html.erb surely it will work - Sagar Pednekar
you need to provide the exact error you're facing. Also, using linux instead of windows might help - Vedant Agarwala
What are you trying to do that doesn't work? Can you show a minimal example of the view code you're trying to use? What happens if you try using bootstrap in a fresh rails app, can you get it to work there? - Simple Lime
Could you provide more details? What makes you believe that Bootstrap didn't install correctly? - emptywalls

3 Answers

2
votes

Maybe try this one:

1) Gemfile

# Add these gems. Rails is not including jQuery by default.
# You need to include it to use all bootstrap options.
gem 'bootstrap'
gem 'jquery-rails'



2) app/assets/javascripts/application.js

jquery3, popper, and bootstrap are the ones for bootstrap

//= require jquery3
//= require popper
//= require bootstrap

//= require rails-ujs
//= require turbolinks
//= require_tree .



3) app/assets/stylesheets/application.scss

@import 'bootstrap'; // assuming you changed to SCSS from CSS


4) Run bundle and restart your server

This is a working repo with Rails 5.2 and Bootstrap 4 https://github.com/HoracioChavez/bootstrap-sample
Tested on macOS

1
votes

You can try this example. It works for me in my project.

In your Gemfile:

gem 'bootstrap-sass'
gem 'jquery-rails'

In your app/assets/javascripts/application.js

//= require rails-ujs
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require bootstrap-sprockets
//= require_tree .

In your /app/assets/stylesheets/application.scss

*= require_tree .
*= require_self
*/

@import "bootstrap-sprockets";
@import "bootstrap";

After you install all gems and make above configurations you can try to test your bootstrap work with this bootstrap dropdown button. Hope it helps you.

Also, please note, that I used bootstrap 3 and worked on Linux Ubuntu.

0
votes

for rails v5.2.0.

  1. All you need is to ensure you have the gem 'bootstrap-sass' AND gem 'jquery-rails' in the gem file. Bootstrap requires JQuery. Back in other rails versions i.e v4.x you would have to include alot of other gems but not anymore in this version they are the default except the bootstrap-sass and jquery-rails gem.
  2. run bundle install to install the gems
  3. Then change the default manifest file app/assets/stylesheets/application.css filename to app/assets/application.scss(.sass) because we need to import (load and execute) said file, css cant do that also because the line we intend to include is sass syntax not css syntax.
  4. include @import"bootstrap" in the stylesheet manifest file (application.scss) and prepend //= require jquery in application.js. This affects affects the app/views/layouts/application.html.erb the standard place for all your layout used by all templates in the controller. In older versions here you would have to require other extensions eg. turbolink in order for bootstrap to work effectively and efficiently but no in this version.

Your done. All your web pages are now bootstrap integrated.