我正在安装 bootstrap-sass gem,我需要将 Bootstrap 导入 application.css.scss 中,如下所示:
@import "bootstrap";
但是我在资产/样式表中找不到它。我只是创建它吗?我的 Rails 应用程序会加载此文件吗?
我确实安装了 sass-rails:
gem 'sass-rails', '~> 4.0.0'
我把它放在我的样式中.css.scss:
@import 'bootstrap';
@import 'bootstrap/responsive';
宝石文件:
group :assets do
gem 'bootstrap-sass', '~> 2.3.2.0'
end
任何帮助将不胜感激。
从评论中重新发布我的答案。
默认情况下,application.css.scss在Rails应用程序中不存在,即使包含sass-Rails也是如此。您可以删除应用程序.css并创建应用程序.css.scss并使用它。
同样在 rails 3 中,在资产组内声明的任何 gem 将仅包含在开发和测试环境中。
Rails 3 中的 application.rb。
if defined?(Bundler)
# If you precompile assets before deploying to production, use this line
Bundler.require(*Rails.groups(:assets => %w(development test)))
# If you want your assets lazily compiled in production, use this line
# Bundler.require(:default, :assets, Rails.env)
end
Rails 4 中的 application.rb。
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env)
尝试将 gem 声明移出资产组,它应该可以工作。
开始,新的 Rails 项目将已经配置为使用 Sass(所以如果你使用的是 3.1,你不需要添加该 gem)。如果要升级到 Rails 3.1,则需要将以下内容添加到 Gemfile 中。
您可以在样式表文件夹中创建它,并向其添加以下行。
/* ...
*= require_self
*= require_tree .
*/
然后在您的视图中添加
<%= stylesheet_link_tag "application", :media => "all" %>
还要确保您遵循本指南
尝试将"bootstrap-sass"的要求语句添加到 config.ru 文件中。工作 config.ru 如下所示。
# This file is used by Rack-based servers to start the application.
require ::File.expand_path('../config/environment', __FILE__)
require 'bootstrap-sass' #require statement of bootstrap-sass
run Rails.application