简体   繁体   中英

Rails + Twitter Bootstrap: File to import not found or unreadable: twitter/bootstrap

I am trying to set up Rails app with Twitter Bootstrap (the gem twitter-bootstrap-rails ), but I still cannot get over the error

File to import not found or unreadable: twitter/bootstrap.

I found this issue on official Github of the gem, but none of solution from there have worked for me. Here's my setup: Gemfile

gem "twitter-bootstrap-rails"
gem 'font-awesome-rails'
gem 'sass-rails',   '~> 3.2.3'
group :assets do
  #gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'
  gem 'therubyracer', :platforms => :ruby
  gem 'uglifier', '>= 1.0.3'
end

application.css

 *= require_self
 *= require bootstrap_and_overrides
 *= require font-awesome
 *= require_tree .

bootstrap_and_overrides.css.sass

@import "twitter/bootstrap";
@import "twitter/bootstrap/bootstrap";
@import "twitter/bootstrap/responsive";

// Font Awesome
@import "fontawesome";

// Glyphicons
@import "twitter/bootstrap/sprites.scss";

What am I missing for correct set up?

Thanks

我们有同样的问题,我刚刚重新启动rails服务器,它工作

If you already attempted to shut down the server and restart it, then your problem may be the cached css file that is generated from your sass file. The reason for this may be some varient of live reload which pre-renders several of the scss/haml type files. If that isn't the case then

  1. Read the error message and determine the scss file that is causing the error.
  2. Locate the css file that is generated along the sass file, (ie custom.css.scss would generate custom.css).
  3. Delete that file, refresh the page and if this files delete the entire cache found under assets/stylesheets and temp/cache)

For some reason I had to explicitly require the gem to get it working. As suggested in this github issue comment to fix a similar error with bootstrap-sass, it's likely the gem is not loaded automatically. Add require "twitter-bootstrap-rails to eg config/application.rb file to explicitly require it.

Downgrade the bootstrap-sass gem to v2.3.2 like so: gem 'bootstrap-sass', '2.3.2'

I had done a bundle upgrade which upgraded the bootstrap gem. This (version downgrade) fixed the problem for me.

我如何使它工作的方式只是更改Twitter Bootstrap gem - 我使用了bootstrap-sass gem,在Github页面上描述了所有内容,我没有发现任何问题。

你有没有尝试编译资产?

    rake assets:precompile

I solved this issue by adding gem 'bootstrap-sass', '3.0.2.1' in my Gemfile (per the recent docs). Make sure you run bundle install afterwards.

I found this response as I was searching for a problem with Michael Hartl's RailsTutorial.org program. I had inadvertently allowed the sprockets gem to be upgraded to 2.12.1 (it was locked in Gemfile.lock). Force downgrading it to 2.11.0 fixed this error and allowed the older bootstrap-sass (2.3.2.0) gem to work correctly.

Back to learning!!

Nothing here worked for me. I gave up, downloaded Bootstrap itself, put the files in my assets, and included them in my CSS. That fixed it.

add following gem in asset group and bundle install

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

Try adding

gem 'sass-rails'

to your Gemfile

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM