0

I want my site to change some basic colors, when the site loads from different domains.

Right now I'm setting a bunch of configuration values in a Rails initializer as follows:

if `hostname` == 'example1.org'
    set_plaoul_config
elsif `hostname` == 'example2.org'
    set_gracilis_config
elsif `hostname` == 'example3.org'
    set_wodeham_config
else
    set_plaoul_config
end

The functions referenced here will set a variety of Rails.application.config settings, see the snippet below:

Rails.application.config.biography = true
Rails.application.config.bibliography = true
Rails.application.config.timeline = true
Rails.application.config.about = true
Rails.application.config.blog = false

But I'm wondering if anyone can think of a way that I can set a basic a config setting to effect a global sass variable in my sass style sheets.

For example:

Rails.application.config.dark-color = #BBCEBE

Right now /app/assets/stylesheets/application.css.sass contains some basic theme variables, as follows:

* site theme colors
$dark-color:                #BBCEBE
$light-color:               #E6EDE8
$text-color:                black
$text-bgcolor:              white

I wish there was a way to change the values of these variables based on a config setting set when the Rails app initializes.

For example, I wish I could do this in my Sass file:

    $dark-color: Rails.application.config.dark-color

(I know that I can't do this, I'm just trying to illustrate my desired behavior)

For me the problem is I can't see a way to pass Rails information to Sass.

Ideas?

Jeff
  • 3,943
  • 8
  • 45
  • 68
  • I found this: http://stackoverflow.com/questions/7653381/use-ruby-rails-variables-inside-sass-and-less – Jeff Mar 25 '15 at 18:01

1 Answers1

1

See: How can I use Ruby/Rails variables inside Sass?

Just add .erb to your sass stylesheet filename. Then use variables as normal:

<%= Rails.application.config.dark-color %> 
Community
  • 1
  • 1
Jeff
  • 3,943
  • 8
  • 45
  • 68