Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7440737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:53:55+00:00 2026-05-29T10:53:55+00:00

I am working on a Rails 3.1 app and am happily using SASS and

  • 0

I am working on a Rails 3.1 app and am happily using SASS and CoffeeScript. I particularly like the SASS extensions of variables and imports. I have constructed a single _global-settings.css.scss file which contains ALL of the hex constant values I use throughout all of my stylesheets. This gives me a single place to manage colors, fonts and layout dimensions. Very DRY.

But, if I wish to use JQuery to tweak my css dynamically, I no longer have access to my css compile-time variables, and must reproduce the same data as a JSON hash in a .js.coffee file. Not DRY at all.

Here is my question: Before I go off and build a rake task to munge my css settings file into an equivalent CoffeeScript hash, does anyone have a more clever idea? Like hiding all the values in a hidden div in an html file?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T10:53:56+00:00Added an answer on May 29, 2026 at 10:53 am

    You’d have an easier time moving your CSS configuration into Ruby and then sending your _global-settings.css.scss and a small piece of CoffeeScript through ERB. Then you have your settings in place and you can access them everywhere.

    Somewhere in Ruby you’d have this:

    CSS_SETTINGS = {
        :text_color        => '#333',
        :text_color_hilite => '#f33',
        :font_size         => '14px',
        #...
    }
    

    Then rename your _global-settings.css.scss to _global-settings.css.scss.erb and use things like this inside it:

    $text-color: '<%= CSS_SETTINGS[:text_color] %>';
    // ...
    

    And inside a global_settings.js.coffee.erb you could have this:

    window.app.global_settings = <%= CSS_SETTINGS.to_json.html_safe %>
    

    You could even write a simple view helper that would SASSify a Hash:

    def sassify(h)
        h.map do |k, v|
            # You might want more escaping for k and v in here, this is just
            # a simple proof of concept demo.
            [ '$', k.to_s.gsub('_', '-'), ': ', "'#{v}'", ';' ].join
        end.join("\n")
    end
    

    and then you could say this in your _global-settings.css.scss.erb:

    // Import global CSS settings.
    <%= sassify(CSS_SETTINGS).html_safe %>
    

    You could also monkey patch a to_sass into Hash and use CSS_SETTINGS.to_sass but that’s probably taking things one step too far.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have jquery working on my Rails app using the gem 'jquery-rails' . I
I'm working on a Rails app using CanCan for RBAC and I only have
Now that I have a working Rails 3 web app, I'd like to make
I am working on rails 3 app and using the koala gem to get
I'm working on a Rails app, where I'm using page caching to store static
I have a rails app that is working fine except for one thing. When
I have a working rails app that uses imagemagick commands on my local mac
I'm working on a rails app and using spine, I want to use the
I have a working private-beta Rails app on mydomain.com. All the routes work. However,
I am working on a small rails app and have a problem with ruby's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.