1

I'm attempting to change my application.bootstrap.scss file to application.bootstrap.scss.erb so I can do an ERB case statement to give users a different set of variables depending on the skin they chose with their account.

The website is still appearing on refresh, but none of the CSS is updating. In my bin/dev server I am getting this error:

Error reading app/assets/stylesheets/application.bootstrap.scss: no such file or directory.

I have added this line to my environments/development.rb as recommended in this post:

config.serve_static_assets = false

And I added this line to my manifest.js:

//= link application.bootstrap.scss.erb

Here's the code I have in my assets/stylesheets/application.bootstrap.scss:

<% user_skin = "Ravenclaw Dark" %>

<% case user_skin %>
<% when "Ravenclaw Dark" %>
  @import 'ravenclaw-dark';
<% else %>
  @import 'ravenclaw-light';
<% end %>

Which references ravenclaw-dark.scss and ravenclaw-light.scss files that look like this:

$color-background: #fff !important;          /* Main background */
$color-text: #000 !important;                /* Main text (contrast bg) */

$color-background-alt: #b9b8b6 !important;   /* Alternate background */
$color-text-alt: #0E1A40 !important;         /* Alternate text */

$color-admin: #FEC601 !important;            /* CTAs & accents (main/opp txt ok) */
$color-accent-main: #1567B3 !important;      /* Good with main/opp text */
$color-accent-subtle: #8CA7B0 !important;    /* Subtle (main/opp text) */

$color-bad: #983C3C !important;              /* both text */
$color-good: #2C8431 !important;             /* both text */

Can anyone see where I'm going wrong?

Liz
  • 1,369
  • 2
  • 26
  • 61

1 Answers1

1

Assets don't work that way, they're compiled into static files, they're not passed through the ruby logic each time. So in order to have what you want you would need to create an endpoint (in your config/routes.rb) that points to a controller action that returns a CSS file - and then you can have an ERB view that generates that CSS.

...but for this it's probably better to put that logic inside your layout file and just use the stylesheet_link_tag to pull in the different theme stylesheets. Take a look at the Themes in Rails app SO post for some more details.

smathy
  • 26,283
  • 5
  • 48
  • 68