Rails没有使用生成的CSS文件

时间:2022-01-25 01:17:00

I've got a Rails 3.1 application. I generate a Controller, just to show what's happening:

我有一个Rails 3.1应用程序。我生成一个Controller,只是为了显示正在发生的事情:

$ rails generate controller Rocks index show edit
      create  app/controllers/rocks_controller.rb
       route  get "rocks/edit"
       route  get "rocks/show"
       route  get "rocks/index"
      invoke  haml
      create    app/views/rocks
      create    app/views/rocks/index.html.haml
      create    app/views/rocks/show.html.haml
      create    app/views/rocks/edit.html.haml
      invoke  rspec
      create    spec/controllers/rocks_controller_spec.rb
      create    spec/views/rocks
      create    spec/views/rocks/index.html.haml_spec.rb
      create    spec/views/rocks/show.html.haml_spec.rb
      create    spec/views/rocks/edit.html.haml_spec.rb
      invoke  helper
      create    app/helpers/rocks_helper.rb
      invoke    rspec
      create      spec/helpers/rocks_helper_spec.rb
      invoke  assets
      invoke    coffee
      create      app/assets/javascripts/rocks.js.coffee
      invoke    scss
      create      app/assets/stylesheets/rocks.css.scss

Great. Looking good. Generated app/assets/stylesheets/rocks.css.scss. Just what I wanted.

大。看起来不错。生成的app / assets / stylesheets / rocks.css.scss。正是我想要的。

Now, navigating to http://localhost:3000/rocks/index, I examine the source and see:

现在,导航到http:// localhost:3000 / rocks / index,我检查源代码并看到:

  <head> 
    ...
    <link href="/assets/application.css?body=1" media="screen" rel="stylesheet" type="text/css" /> 
    <script src="/assets/jquery.js?body=1" type="text/javascript"></script> 
    <script src="/assets/jquery_ujs.js?body=1" type="text/javascript"></script> 
    <script src="/assets/rocks.js?body=1" type="text/javascript"></script> 
    <script src="/assets/application.js?body=1" type="text/javascript"></script> 
    ...
  </head>

rocks.css is missing, and I have no idea why. Has anyone encountered something like this before?

rocks.css丢失了,我不明白为什么。有没有人遇到过这样的事情?

1 个解决方案

#1


3  

Your application.css should have this lines:

你的application.css应该有这样的行:

/*
 * This is a manifest file that'll automatically include all the stylesheets available in this directory
 * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
 * the top of the compiled file, but it's generally better to create a new file per style scope.
 *= require_self
 *= require_tree . 
*/

the most important:

最重要的:

*= require_tree . 

Then rocks.css should be included by the application.css, that's an advantage using assets

那么rocks.css应该包含在application.css中,这是使用资产的一个优势

#1


3  

Your application.css should have this lines:

你的application.css应该有这样的行:

/*
 * This is a manifest file that'll automatically include all the stylesheets available in this directory
 * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
 * the top of the compiled file, but it's generally better to create a new file per style scope.
 *= require_self
 *= require_tree . 
*/

the most important:

最重要的:

*= require_tree . 

Then rocks.css should be included by the application.css, that's an advantage using assets

那么rocks.css应该包含在application.css中,这是使用资产的一个优势