2

I noticed that after generating a new Rails 4.2 application the order for the requires in application.css has been changed.

 *= require_tree .
 *= require_self

Shouldn't this be the other way around? Even in the Guides it isn't this way...

crispychicken
  • 2,592
  • 2
  • 33
  • 50
  • 1
    I don't have an official line I can quote at the moment, but I believe `require_self` literally includes the manifest file itself and any JS or CSS you've included in body of the file, but the rest of the manifest merely indicates which files to load. You can remove `require_self` and still have a normally running application. So in short, you can reverse those lines, or leave it as it, or remove `require_self` if you want, it doesn't make a difference. – Paul Richter Jan 09 '15 at 18:07
  • @PaulRichter It does make a difference,I think . In my application I have explicitly defined the position on top , if I remove it ,the application.css file gets to the bottom and override css rules defined . – Shail Apr 07 '15 at 02:42
  • @shail I'm not sure I fully understand what you described, but yes when I implied "the position doesn't matter", I was mistaken. If you take a look at my answer below I corrected that statement based on some research I found. – Paul Richter Apr 07 '15 at 13:26

2 Answers2

4

The change was made in order to allow styles defined in application.css to override previously included styles.

See Rails issue #11639 and this commit which changed the order of the require instructions.

janfoeh
  • 10,243
  • 2
  • 31
  • 56
1

As described in the official documentation here, and also explained in this SO answer here:

This puts the CSS contained within the file (if any) at the precise location of the require_self call.

This is slightly different than what I wrote in the comments since, as indicated by the above quote, the JS or CSS in the manifest will be inserted at the location of require_self. This becomes important if you have later assets that depend on something you wrote in the manifest.

Of course if you're doing that though, it would probably be better to place that "inline" asset in a separate file anyways, just to keep the manifest clean.

Community
  • 1
  • 1
Paul Richter
  • 10,908
  • 10
  • 52
  • 85