How to Use Ruby/Rails Variables Inside Sass

How can I use Ruby/Rails variables inside Sass?

You can add .erb extention to your .sass file and then add your variables just like in regular .erb file:

<%= APP_CONFIG[:yourkey] %>

More information:

  • http://guides.rubyonrails.org/asset_pipeline.html#preprocessing
  • http://guides.rubyonrails.org/asset_pipeline.html#coding-links-to-assets
  • http://rwilcox.tumblr.com/post/9038701675/sass-variables-and-the-rails-3-1-asset-pipeline

Carry Sass variables across all stylesheet files in Rails

You should rename all files that will use the shared variables to start with _.
This will render the other files in context of partial files, which will use the previous declared variables in @import 'site_settings'. So you will have site_settings.scss and quickrails/_general.scss, quickrails/_media_query.scss and so on.

Those imports are considered partials, that is why the name should start with underscore, but when importing you use without it. Here is a material about this:

Why put in front of the file name "_" or "_" in scss/css?

How to easily pass a variable into a .sass file?

The recommended way to do this is to define a custom Sass function (see the documentation) and use the :custom option to pass in your specific variables.

compiling with the variables in _vars.scss ruby on rails 2.0

The error message is pretty clear.
Sass tried to find variable $screen-sm-max on file _styles.scss but failed.

Try to add

$screen-sm-max: 42;

on file _styles.scss.

And see if that solves the problem.

Accessing Rails.env inside Sass

Make sure it is name.css.scss.erb

Also, here is a good answer https://stackoverflow.com/a/7653451/643500



Related Topics



Leave a reply



Submit