Ruby-on-rails – Stylesheet_link_tag does not work as expected

ruby-on-railsstylesheet

I am using Rails 3.1.1 and have stylesheets in my assets-folder as:

  • application.css
  • abc.css.scss
  • def.css.scss
  • etc

also in a subfolder /admin/ I have admin.css. All in all

  • application.css
  • admin/admin.css
  • abc.css.scss
  • def.css.scss
  • etc.

Now, by using:

<%= stylesheet_link_tag 'application' %>

…(which seems to be default) I would expect it to only load the application.css but it loads not only application.css but also abc.css.scss etc.

<link href="/assets/application.css?body=1" media="screen" rel="stylesheet" type="text/css" />
<link href="/assets/admin/admin.css?body=1" media="screen" rel="stylesheet" type="text/css" />
<link href="/assets/affiliate_types.css?body=1" media="screen" rel="stylesheet" type="text/css" />
<link href="/assets/benefits.css?body=1" media="screen" rel="stylesheet" type="text/css" />
<link href="/assets/buy_this_ifs.css?body=1" media="screen" rel="stylesheet" type="text/css" />

Additionally it loads admin.css in the /admin/-subfolder. As far as I understand recursive is defaulted to false, so it shouldn't, right?

Anyway, I tried:

  <%= stylesheet_link_tag 'application', :recursive => false %>

which still loaded the admin/admin.css. Same result as above in other words.

If I try:

  <%= stylesheet_link_tag :all %>

it just loads an "all.css" that it cannot find.

I have tried variants of :cache => true and :cache => false to no avail.

My questions:

  1. How do I make rails import all stylesheets (application.css, abc.css.scss etc) but NOT admin/admin.css?

  2. How do I make admin.css inherit from application.css? I just want to have the unique features of the admin interface (such as a different body color) in there.

Best Answer

The problem was due to the:

 *= require_tree . 

in the application.css-file itself. I thought that didn't do anything since it was inside comment brackets.

Related Topic