I am trying to implement user-chosen skins in my Rails app, as recommended in this SO post.
I have my skins in a folder in app/assets/stylesheets/skins
and each one is structured like this:
$color-background: #F0E6DA !important; /* Main background */
$color-background-alt: #a8a198 !important; /* Alternate background */
$color-background-box: #ffffff !important; /* Box Background */
$color-text: #000000 !important; /* Main text (contrast bg) */
$color-text-alt: #653D3D !important; /* Alternate text */
$color-text-box: #000000 !important; /* Box text (contrast box-bg) */
$color-admin: #225e51 !important; /* CTAs & accents (main/opp txt ok) */
$color-accent-main: #842a57 !important; /* Good with main/opp text */
$color-accent-subtle: #a86989 !important; /* Subtle (main/opp text) */
$color-bad: #983C3C !important; /* both text */
$color-good: #16537e !important; /* both text */
The rest of my SCSS is in my application.bootstrap.scss
file, where the CSS references these variable names.
I reference this in my application.html.erb
like this:
<%= stylesheet_link_tag "#{@current_theme}", "data-turbo-track": "reload" %>
<%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
And have this in my application_helper.rb
:
module ApplicationHelper
def current_theme
if @current_user && @current_user.chosen_skin != ( nil || "" )
@current_theme = @current_user.chosen_skin
else
@current_theme = 'skins/default'
end
end
end
I added the following to my assets.rb
(and restarted my server):
Rails.application.config.assets.precompile += %w( skins/* )
When I try to load a page, I get an error saying Error: Undefined Variable.
pointing to the first time my application.bootstrap.scss
references a variable from one of the skins
files. (Yes, I double checked that I do, in fact, have one called default.scss.css
.
When I look at the rendered line in the application header, it just shows up like this:
<link rel="stylesheet" href="" data-turbo-track="reload" />
<link rel="stylesheet" href="/assets/application-3484df6482827f75364ce1ebdc6829c5125776d4a06144b1a5c7a9fe2e71f7b9.css" data-turbo-track="reload" />
Can anyone see where I'm going wrong here?