Alan Coromano
Alan Coromano

Reputation: 26008

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

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)‌​

Upvotes: 3

Views: 13097

Answers (5)

Praveen Pandey
Praveen Pandey

Reputation: 1

Follwing steps worked for me:

  1. Move twitter-bootstrap-rails gem from outside of :assets in gemfile
  2. replace the twitter bootstrap gem by this (gem "twitter-bootstrap-rails", '~> 2.2.6') in gemfile
  3. bundle update
  4. restart server and test

Upvotes: 0

Alexander Suraphel
Alexander Suraphel

Reputation: 10603

Restarting the server worked for me.

Upvotes: 13

Sandeep Roniyaar
Sandeep Roniyaar

Reputation: 204

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

Upvotes: 2

suresh gopal
suresh gopal

Reputation: 3156

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.

Upvotes: 11

zakelfassi
zakelfassi

Reputation: 2966

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

Upvotes: 6

Related Questions