14

I was trying to play with Twitter Bootstrap Basics using Rails 4.0.0.rc1 and ruby 1.9.3p392.

Then I try to access http://localhost:3000/products

I'm having error:

'twitter/bootstrap/bootstrap.less' wasn't found.

Please see attached screenshot.

Code available at https://github.com/tenzan/twitter-bootstrap.git

enter image description here

Ilya Khokhryakov
  • 3,686
  • 1
  • 19
  • 22
Askar
  • 5,784
  • 10
  • 53
  • 96
  • 1
    try to remove gem 'sass-rails', '~> 4.0.0.rc1' from Gemfile and bundle – Said Kaldybaev May 21 '13 at 08:49
  • I've commented out 'sass-rails' and run "bundle update" and restarted server - nothing changed – Askar May 21 '13 at 09:09
  • https://github.com/tenzan/twitter-bootstrap/blob/master/Gemfile – Askar May 21 '13 at 09:28
  • 13
    Rails 4 removed the need for an `:assets` group in the Gemfile. Do you have a specific reason for leaving that in? – Marcelo De Polli May 21 '13 at 10:35
  • No any specific reason to have :asset. It didn't work the other way so I just tried this way. I'm new to RoR. Now I've removed :assets following your advice and added *= require bootstrap_and_overrides to the application.css @shrikant1712 advised below and it worked! Thanks! – Askar May 21 '13 at 11:34

6 Answers6

32

I'm going to answer this noting that I am working on ruby 2 / rails 4 application (NOT rails 3)

Requiring Bootstrap LESS (bootstrap_and_overrides.css.less) in your application.css is meaningless here, because the pipeline comes already with "require_tree ." which automatically includes everything inside the folders of the asset pipeline.

After pulling my hair for several hours, I found that removing the 3 required gems from the group :asset in the Gemfile is the only way to fix it

So, Do Not do this in you Gemfile:

group :assets do
  gem "therubyracer"
  gem "less-rails"
  gem "twitter-bootstrap-rails"
end

And instead DO this:

gem "therubyracer"
gem "less-rails"
gem "twitter-bootstrap-rails"
Aghyad
  • 349
  • 1
  • 3
  • 4
13

The Bootstrap gem comes with it's own bundled version of Bootstrap which it will take responsibility for importing. Don't import the Bootstrap gem in the :assets group, or the gem assets won't be found.

Note that the assets group has been removed in Rails 4.

superluminary
  • 47,086
  • 25
  • 151
  • 148
12

You have to require Bootstrap LESS (bootstrap_and_overrides.css.less) in your application.css

/*
 *= require bootstrap_and_overrides
 */
shrikant1712
  • 4,336
  • 1
  • 24
  • 42
  • 15
    I had the same problem and this answer is not actually correct. By default Rails adds `require_tree .` in your application.css which loads everything including bootstrap_and_overrides. The problem was that you had nested all the Bootstrap gems in an :assets group in your Gemfile. Once I removed that, it worked. The right answer is actually from @depa. :) – Leonard Teo May 29 '13 at 00:45
  • 1
    thanks for your kind information.actually I am not worked with Rails 4.0.0.rc1 that much – shrikant1712 May 29 '13 at 10:31
1

I was using Bootstrap 2 and less on Rails 4.0.1. I decided to upgrade to Bootstrap 3 but "twitter-bootstrap-rails" is still on Bootstrap 2. There are a few gems available but I found the simplest approach was to add the css, js and fonts manually (followed these instructions Using bootstrap 3 with rails 4).

Follow these instructions, ensure "therubyracer" and "less-rails" gems are installed and then a few more steps are required to get less working with bootstrap 3 and rails 4:

  • Download Bootstrap 3 source (Bootstrap source)
  • Create directory "/vendor/assets/stylesheets/bootstrap"
  • Copy contents of bootstrap source "less" directory (lots of less files) to "/vendor/assets/stylesheets/bootstrap"
  • Create "bootstrap_and_override.css.less" in "app/assets/stylesheets". Import "bootstrap.less" into "bootstrap_and_override.css.less", example of mine including a couple of test customisations:

    @import "../../../vendor/assets/stylesheets/bootstrap/bootstrap.less";
    @navbar-height: 120px;
    @body-bg: #F7911B;
    

Hope this is useful to anyone wanting to try Bootstrap 3 with less.

Peter Todd
  • 8,561
  • 3
  • 32
  • 38
0

for me, less-rails gem was missing from Gemfile and adding it and running bundle solved the issue.

Sachin Singh
  • 7,107
  • 6
  • 40
  • 80
0

You might have missed to run
rails g bootstrap:install less
It worked like a charm