2

I've been learning Ruby on Rails for the last few days and i'm following tutorials from a book. I'm working on an app which requires importing bootstrap however i'm having trouble installing it into my project.

I'm using Ruby version 2.3.1 and Rails version 5.1.1 and i'm using the cloud9 coding environment

I create a new app with the following command:

rails new bootstrap_app

The next instruction is to "add the bootstrap gem to the gemfile" with the following command:

gem 'bootstrap‐sass' , '~> 3.3.6'

I do this and I get the following error:

ERROR:  While executing gem ... (Gem::CommandLineError)
    Unknown command bootstrap-sass,

I looked up this error and I found it on stackoverflow here however "restarting the server" didn't work in my case.

The next instruction in the tutorial, is the command

bundle install

I do this and it tells me a list of dependencies that are installed (bootstrap is not listed)

I tried the command gem install bootstrap-sass and it said it installed the gem successfully however when i try to import bootstrap in my CSS file as follows:

@import "bootstrap‐sprockets" ;
@import "bootstrap";

i get the following error:

ActionController::RoutingError (No route matches [GET] "/assets/bootstrap%E2%80%90sprockets"):

any ideas on how i can get this working? Thanks

Sarah
  • 1,943
  • 2
  • 24
  • 39
  • 3
    Sounds like you copy/paste `gem 'bootstrap‐sass' , '~> 3.3.6'` into your command line. But you need to open the `Gemfile` file and add the line there. – Wukerplank Jun 06 '17 at 15:03
  • @Wukerplank That makes more sense thank you. I see the Gemfile now in the app folder. So I have added the line gem 'bootstrap‐sass' , '~> 3.3.6' to the Gemfile and I have run bundle install but i'm getting an error: "Could not find gem 'bootstrap‐sass (~> 3.3.6)' in any of the gem sources listed in your Gemfile.".. but the source is listed at the top of the Gemfile as follows: source 'https://rubygems.org' ..any ideas? – Sarah Jun 06 '17 at 15:21
  • 1
    Put both these in your `Gemfile`: `gem 'bootstrap-sass', '~> 3.3.6' gem 'sass-rails', '>= 3.2'` then run `bundle install`. – t56k Jun 06 '17 at 16:01
  • Thanks @CD-RUM but the sass-rails was already in my Gemfile. gem 'sass-rails', '~> 5.0' and i did run bundle install after. it successfully installed the bundle but i am getting the error "File to import not found or unreadable: bootstrap‐sprockets." – Sarah Jun 06 '17 at 16:55

1 Answers1

1

As CD-RUM stated, you will need to add both the gem bootstrap-sass & gem sass-rails in to your Gemfile. I would also suggest adding gem 'sprockets', '2.11.0' as well since the newer version of sprockets that comes with rails 5 has had some issues working well with Bootstrap. Then run bundle install.

You will also want to rename your application.css file to application.scss and add the import files (@import "bootstrap-sprockets" & @import "bootstrap") there . Now restart your server.

Read through the Ruby on Rails installation instructions here: bootsrap-sass gem & if you're still having issues consider changing the version of the bootstrap-sass gem to an earlier version (I use gem 'bootstrap-sass', '~> 3.3.5.1') since some people seem to experience version conflicts.

Belder
  • 768
  • 1
  • 10
  • 17
  • Thanks @BrandonElder but the sass-rails was already in my Gemfile. gem 'sass-rails', '~> 5.0'. I have followed all the guidelines including renaming application.css file to application.scss and also taking out *= require_self and *= require_tree in application.scss file and using import. I also added //= require bootstrap‐sprockets to application.js however still no luck. The project works when I take out import "bootstrap‐sprockets" ; and just use import "bootstrap"; but its not really ideal to leave it out. I appreciate all your help. – Sarah Jun 06 '17 at 16:52
  • Hmm.... Do you have the sprockets gem in your Gemfile? I would try adding `gem 'sprockets', '2.11.0'` – Belder Jun 06 '17 at 16:55
  • Thanks. Ok ive just added what you said to the Gemfile and ran "bundle install" again. and then restarted my server but I still get an error saying "File to import not found or unreadable: bootstrap‐sprockets." hmm – Sarah Jun 06 '17 at 17:08
  • It might also help to not specify the version of `gem 'sass-rails'`. Rails will find the newest version of sass-rails gem that works. – Belder Jun 06 '17 at 17:09
  • Hmm... yeah that's strange. I can't think of anything else that might help at the moment. Sounds like you've done everything that I normally do when adding bootstrap to a Rails project. – Belder Jun 06 '17 at 17:11
  • Could be some kind of compatibility issue with the gem versions. Try changing to `gem 'bootstrap-sass', '~> 3.3.5.1'`. I'm pretty sure that the latest version has some bugs but I could be wrong. – Belder Jun 06 '17 at 17:15
  • Thanks. I just tried that but had no luck. I was wondering what version of ruby and also rails are you using? – Sarah Jun 06 '17 at 17:22
  • Dang...I'm stumped. I'm using Rails 5 and I believe Ruby 2.3.1 – Belder Jun 06 '17 at 17:26
  • Ok thanks. Actually i've just tried creating a new project and have followed the steps again to add bootstrap including using the version you mentioned: 'bootstrap-sass', '~> 3.3.5.1' and it is running fine on the server so far. Maybe it didn't work in the last project because I was trying to install it mid-way through having worked on the project. So fingers crossed it will keep running successfully in this project after i incorporate some bootstrap styling etc. I'll let you know. Thanks for all the help. – Sarah Jun 06 '17 at 17:34
  • Oh awesome! Glad I could help Sarah. Don't forget to accept my answer if it was helpful : ) I just added bootstrap to a new project last night and that is the process I used. Also as a side note for your assets to work in production, you may have to change the line in `/config/environments/production.rb` from `config.assets.compile = false` to `config.assets.compile = true`. Worth looking into at least. – Belder Jun 06 '17 at 17:44
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/145999/discussion-between-sarah-and-brandonelder). – Sarah Jun 06 '17 at 18:15