I see that in development environment in rails 3.1 the css are loaded in alphabetic order and not in the order I want. I want a particular css file to be at the end so it over-writes any styles given to the class before. How can we achieve that?
Asked
Active
Viewed 1.2k times
25
-
the simplest trick is to rename it. `zzz-the_last.css` – Sergio Tulentsev Jan 17 '12 at 07:17
-
1I did the same for now !!! But that is a hack !! Is there a Rails way? – phoenixwizard Jan 17 '12 at 07:19
2 Answers
43
You can actually do something like:
/*
*= require 'reset'
*= require_self
*= require_tree .
*/
in your application.css file. This allows you to specify any number of stylesheets, such as a reset, to come before the tree without having to specify each individual file. The single quotes around reset are optional.
Not trying to resurrect an old thread, just thought this might be helpful for some.

graytist
- 576
- 1
- 3
- 5
-
5It appears that this also removes that file from being loaded again later in the chain (to prevent double-loading), at least in Rails 4. – Erik Trautman Apr 04 '14 at 04:46
18
It is better to specify the order of each and every files manually:
/*
* 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 reset
*= require groups
*= require the_last
*

Arun Kumar Arjunan
- 6,827
- 32
- 35
-
-
So I myself load wherever I need the stylesheet and I get it in my order. Right? – phoenixwizard Jan 17 '12 at 07:24
-
But this is giving error *= require reset *= require groups *= require the_last //This is throwing errors like: "couldn't find file 'the_last'" – phoenixwizard Jan 17 '12 at 07:29
-
4You need to change `reset`, `groups` and `the_last` with the names of your css files - this is only an example to show how it would work. – nmott Jan 17 '12 at 11:04