新手问题 production 模式下 @import "bootstrap"不能生效

besfan · 2014年04月13日 · 最后由 besfan 回复于 2014年04月13日 · 3895 次阅读

我在跟着http://railstutorial-china.org/chapter5.html 学习,使用 bootstrap 的时候,发现在 development 下页面的布局是正常的,bootstrap 被导入了,而 production 下 bootstrap 没有被导入。 求各位大神帮忙看一下。

使用 firebug 看到/assets/application-1cd2bb7dabfed08f435790f666470fe7.css

<!DOCTYPE html>
<html>
<head>
  <title>The page you were looking for doesn't exist (404)</title>
  <style>
  body {
    background-color: #EFEFEF;
    color: #2E2F30;
    text-align: center;
    font-family: arial, sans-serif;
  }
.......

  </style>
</head>

<body>
  <!-- This file lives in public/404.html -->
  <div class="dialog">
    <h1>The page you were looking for doesn't exist.</h1>

    <p>You may have mistyped the address or the page may have moved.</p>
  </div>
  <p>If you are the application owner check the logs for more information.</p>
</body>
</html>

而工程的 public/assets/application-1cd2bb7dabfed08f435790f666470fe7.css 中内容是正常的

/*!
 * Bootstrap v2.3.2
 *
 * Copyright 2012 Twitter, Inc
 * Licensed under the Apache License v2.0
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Designed and built with all the love in the world @twitter by @mdo and @fat.
 */article,aside,details,figcaption,figure, ...
* Bootstrap v2.3.2
 *
 * Copyright 2012 Twitter, Inc
 * Licensed under the Apache License v2.0
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Designed and built with all the love in the world @twitter by @mdo and @fat.
 */article,aside,details,figcaption,figure,...

/app/assets/stylesheets/application.css

/*
 *= require bootstrap
 *= require_self
 *= require_tree .
 */

/home/besfan/Documents/woke_space/sample_app/app/assets/stylesheets/custom.css.scss

@import "bootstrap";

/* mixins, variables, etc. */

$grayMediumLight: #eaeaea;

/* universal */

html {
  overflow-y: scroll;
}
.....

Gemfile

source 'http://ruby.taobao.org'
ruby '2.0.0'

gem 'rails', '4.0.4'

group :development, :test do
  gem 'rspec-rails', '2.13.1'
end
group :test do
  gem 'selenium-webdriver', '2.35.1'
  gem 'capybara', '2.1.0'
  gem 'guard-rspec', '2.5.0'
  gem 'libnotify', '0.8.0'

  gem 'spork-rails', '4.0.0'
  gem 'guard-spork', '1.5.0'
  gem 'childprocess'
end

gem 'sass-rails', '4.0.1'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.1'
gem 'jquery-rails', '2.2.1'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'

group :doc do
  gem 'sdoc', '0.3.20', require: false
end

gem 'pg', '0.17.1'
gem 'therubyracer'
gem 'execjs'
gem 'bootstrap-sass', '2.3.2.0'

用的什么 App Server?默认的 WEBrick 不处理静态文件。可以改配置打开,但这时我一般改用 passenger start

#1 楼 @Rei

非常感谢!使用的是 WEBrick,打开配置就可以了! 在/config/environments/production.rb 中把修改为 config.serve_static_assets = true

需要 登录 后方可回复, 如果你还没有账号请 注册新账号