Rails: Couldn't find a file for 'twitter/bootstrap'

12,787

Solution 1

I solved this issue by using following steps:

  1. Move twitter-bootstrap-rails gem from outside of :assets in gemfile
  2. Update twitter-bootstrap-rails gem version 2.2.6 or just paste below line in your gemfile.

    gem 'twitter-bootstrap-rails', :git => 'git://github.com/seyhunak/twitter-bootstrap-rails.git'

(or)

if twitter-bootstrap-rails 2.2.6 is not working then Use twitter-bootstrap-rails gem latest version.

Solution 2

Restarting the server worked for me.

Solution 3

Just use //= require bootstrap instead of //= require twitter/bootstrap.

Solution 4

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.

so, I suggest you to do some changes in your Gemfile.

Move the following gems from outside of :assets in Gemfile.

do this

gem "therubyracer"
gem "less-rails"
gem "twitter-bootstrap-rails"

instead of this

group :assets do
  gem "therubyracer"
  gem "less-rails"
  gem "twitter-bootstrap-rails"
end
Share:
12,787

Related videos on Youtube

Alan Coromano
Author by

Alan Coromano

Updated on July 29, 2022

Comments

  • Alan Coromano
    Alan Coromano over 1 year

    I'm using twitter bootstrap in my Rails application. It works well in development mode but does not in production. Here is the Gemfile

    source 'https://rubygems.org'
    
    ruby '1.9.3'
    gem 'rails' 
    gem 'jquery-rails'
    gem 'haml-rails'
    gem 'devise'
    gem 'bcrypt-ruby'
    gem 'curb'
    gem 'nokogiri'
    gem 'pg'
    
    group :assets do
      gem 'sass-rails'
      gem 'twitter-bootstrap-rails'
      gem 'uglifier'
    end
    

    When I run it as rails s -e production it gives me the error of

    ActionView::Template::Error (couldn't find file 'twitter/bootstrap'
      (in /home/alex/Documents/ruby_projects/p1/app/assets/javascripts/application.js:15)):
    

    Application.js

    //= require jquery
    //= require jquery_ujs
    //= require twitter/bootstrap
    //= require_tree .
    

    production.rb

    config.serve_static_assets = false
    
    # Compress JavaScripts and CSS
    config.assets.compress = true
    
    # Don't fallback to assets pipeline if a precompiled asset is missed
    config.assets.compile = true
    
    # Generate digests for assets URLs
    config.assets.digest = true
    

    Somebody suggested me to remove gem 'twitter-bootstrap-rails' which I cannot do because I use it or move it outside of group assets which didn't help me either: the application well except the fact that twitter bootstrap files (js and css) weren't loaded at all.

    How do I fix it?

    UPDATE:

    If I use use //= require bootstrap instead of //= require twitter/bootstrap then it gives me cannot load such file -- less (in home/alex/Documents/ruby_projects/pr1/app/assets/stylesheets/bootstrap_and_overr‌​ides.css.less) despite the fact that the file exists.

    And if I rename css.less to css, then I get the next error couldn't find file 'bootstrap_and_overrides' (in /home/alex/Documents/ruby_projects/pr1/app/assets/javascripts/application.js:15)‌​

    • fmendez
      fmendez about 11 years
      I was under the impression that this line: *= require twitter/bootstrap goes into the application.css not application.js. Additionally, for more recent version of the gem it should be: *= require bootstrap_and_overrides within the .css after you're done running: rails g bootstrap:install. Source: github.com/seyhunak/twitter-bootstrap-rails/wiki/…
  • Alan Coromano
    Alan Coromano about 11 years
    it gives me cannot load such file -- less (in home/alex/Documents/ruby_projects/pr1/app/assets/stylesheets‌​/bootstrap_and_overr‌​ides.css.less) despite the fact that the file exists.
  • Alan Coromano
    Alan Coromano about 11 years
    and if I rename cs.less to cs, then I get the next error couldn't find file 'bootstrap_and_overrides' (in /home/alex/Documents/ruby_projects/pr1/app/assets/javascript‌​s/application.js:15)
  • Sikora
    Sikora about 9 years
    It worked for me, but I'm using bootstrap-sass gem instead the mentioned twitter-bootstrap-rails gem.