Ruby-on-rails Rails + Twitter Bootstrap:未找到或无法读取要导入的文件:twitter/bootstrap

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15784769/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 21:44:31  来源:igfitidea点击:

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

ruby-on-railsrubytwitter-bootstrapgemtwitter-bootstrap-rails

提问by user984621

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

我正在尝试使用 Twitter Bootstrap(gem twitter-bootstrap-rails)设置 Rails 应用程序,但我仍然无法克服错误

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 的官方 Github 上发现了这个问题,但是那里没有任何解决方案对我有用。这是我的设置: 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

应用程序.css

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

bootstrap_and_overrides.css.sass

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

谢谢

回答by Harvey Katrina

we had the same problem, i just restarted the rails server and it worked

我们遇到了同样的问题,我刚刚重新启动了 rails 服务器并且它工作正常

回答by jquintana

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

如果您已经尝试关闭服务器并重新启动它,那么您的问题可能是从您的 sass 文件生成的缓存 css 文件。其原因可能是一些实时重新加载的变体,它预渲染了几个 scss/haml 类型的文件。如果不是这样的话

  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, (i.e. 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)
  1. 阅读错误消息并确定导致错误的 scss 文件。
  2. 找到随 sass 文件生成的 css 文件(即 custom.css.scss 将生成 custom.css)。
  3. 删除该文件,刷新页面,如果此文件删除资产/样式表和临时/缓存下的整个缓存)

回答by dantheta

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

出于某种原因,我必须明确要求 gem 使其工作。正如这个 github 问题评论中建议的那样,用 bootstrap-sass 修复类似的错误,很可能 gem 没有自动加载。添加require "twitter-bootstrap-rails到例如 config/application.rb 文件以明确要求它。

回答by user2748756

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

将 bootstrap-sass gem 降级到 v2.3.2,如下所示: 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.

我已经完成了升级 bootstrap gem 的捆绑升级。这个(版本降级)为我解决了这个问题。

回答by Tamara

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.

这里没有什么对我有用。我放弃了,下载了 Bootstrap 本身,将文件放在我的资产中,并将它们包含在我的 CSS 中。那修复了它。

回答by user984621

The way how I made it work was simply changing the Twitter Bootstrap gem - I used the bootstrap-sassgem, where is set up everything as is described on the Github page and I didn't find any problem with.

我的工作方式是简单地更改 Twitter Bootstrap gem - 我使用了bootstrap-sassgem,在那里设置了 Github 页面上描述的所有内容,我没有发现任何问题。

回答by MC2DX

Did you try to compile the assets ?

您是否尝试编译资产?

    rake assets:precompile

回答by Jay Dorsey

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 installafterwards.

我通过添加gem 'bootstrap-sass', '3.0.2.1'我的 Gemfile(根据最近的文档)解决了这个问题。确保您bundle install之后运行。

回答by Joseph Juhnke

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.

我在寻找 Michael Hartl 的 RailsTutorial.org 程序的问题时发现了这个回复。我无意中允许 sprockets gem 升级到 2.12.1(它被锁定在 Gemfile.lock 中)。强制将其降级到 2.11.0 修复了这个错误,并允许旧的 bo​​otstrap-sass (2.3.2.0) gem 正常工作。

Back to learning!!

回去学习!!

回答by beydogan

Try adding

尝试添加

gem 'sass-rails'

gem 'sass-rails'

to your Gemfile

到你的 Gemfile