twitter-bootstrap Rails:找不到“twitter/bootstrap”的文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16127302/
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
Rails: Couldn't find a file for 'twitter/bootstrap'
提问by Alan Coromano
I'm using twitter bootstrap in my Rails application. It works well in development mode but does not in production. Here is the Gemfile
我在我的 Rails 应用程序中使用 twitter bootstrap。它在开发模式下运行良好,但在生产模式下不起作用。这是 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
当我将它作为 rails s -e production 运行时,它给了我错误
ActionView::Template::Error (couldn't find file 'twitter/bootstrap'
(in /home/alex/Documents/ruby_projects/p1/app/assets/javascripts/application.js:15)):
Application.js
应用程序.js
//= require jquery
//= require jquery_ujs
//= require twitter/bootstrap
//= require_tree .
production.rb
生产.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.
有人建议我删除gem 'twitter-bootstrap-rails'我不能做的事情,因为我使用它或将它移到组资产之外,这对我也没有帮助:应用程序很好,除了 twitter 引导程序文件(js 和 css)根本没有加载。
How do I fix it?
我如何解决它?
UPDATE:
更新:
If I use use //= require bootstrapinstead of //= require twitter/bootstrapthen 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.
如果我使用 use//= require bootstrap而不是//= require twitter/bootstrapthen 它会给我cannot load such file -- less (in home/alex/Documents/ruby_projects/pr1/app/assets/stylesheets/bootstrap_and_overr??ides.css.less)尽管文件存在的事实。
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)??
如果我重命名css.less to css,那么我会收到下一个错误couldn't find file 'bootstrap_and_overrides' (in /home/alex/Documents/ruby_projects/pr1/app/assets/javascripts/application.js:15)??
回答by Alexander Suraphel
Restarting the server worked for me.
重新启动服务器对我有用。
回答by suresh.g
I solved this issue by using following steps:
我通过使用以下步骤解决了这个问题:
- Move twitter-bootstrap-railsgem from outside of :assets in gemfile
Update twitter-bootstrap-railsgem version 2.2.6or just paste below line in your gemfile.
gem 'twitter-bootstrap-rails', :git => 'git://github.com/seyhunak/twitter-bootstrap-rails.git'
- 从 gemfile 中的 :assets 外部移动twitter-bootstrap-railsgem
更新twitter-bootstrap-railsgem 版本2.2.6或将下面的行粘贴到您的 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.
如果 twitter-bootstrap-rails 2.2.6 不起作用,则使用twitter-bootstrap-rails gem latest version。
回答by zakelfassi
Just use //= require bootstrapinstead of //= require twitter/bootstrap.
只需使用//= require bootstrap代替//= require twitter/bootstrap.
回答by Sandeep Roniyaar
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.
在 application.css 中要求 Bootstrap LESS (bootstrap_and_overrides.css.less) 在这里没有意义,因为管道已经带有“require_tree”。它会自动包含资产管道文件夹中的所有内容。
so, I suggest you to do some changes in your Gemfile.
所以,我建议你在你的 Gemfile 中做一些改变。
Move the following gems from outside of :assets in Gemfile.
从 Gemfile 中的 :assets 外部移动以下 gem。
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
回答by Praveen Pandey
Follwing steps worked for me:
以下步骤对我有用:
- Move twitter-bootstrap-rails gem from outside of :assets in gemfile
- replace the twitter bootstrap gem by this (gem "twitter-bootstrap-rails", '~> 2.2.6') in gemfile
- bundle update
- restart server and test
- 从 gemfile 中的 :assets 外部移动 twitter-bootstrap-rails gem
- 在 gemfile 中用这个 (gem "twitter-bootstrap-rails", '~> 2.2.6') 替换 twitter bootstrap gem
- 捆绑更新
- 重启服务器并测试

