1

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

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

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

  <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?

1 Answer 1

3

Your application.css should have this lines:

/*
 * 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

Sign up to request clarification or add additional context in comments.

4 Comments

Yup, that did it. Thanks! I think you meant application.css though.
Rails is getting more and more maddening :) but ♪ ♫I'm loving it♪ ♫
One question: Is it possible to only include application.css and the relevant controller CSS file? require_tree adds all CSS files in.
@Mike Sure you can, you can remove that line require_tree . from the manifest file and specify individual files to load and compile into application.css, take a look here ~> guides.rubyonrails.org/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.