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
What Is Ruby'S Double-Colon '::'
Why Is Division in Ruby Returning an Integer Instead of Decimal Value
Ruby Class Instance Variable Vs. Class Variable
How to Write a Switch Statement in Ruby
What Does the (Unary) * Operator Do in This Ruby Code
Why Doesn't Ruby Support I++ or I-- (Increment/Decrement Operators)
What's the Difference Between Equal, Eql, ===, and ==
Rbenv Not Changing Ruby Version
How to Generate a Random String in Ruby
How to Test If a String Is Basically an Integer in Quotes Using Ruby
Combining Implicit Wait and Explicit Wait Together Results in Unexpected Wait Times
How to Parse Json With Ruby on Rails
What Is the Best Method of Handling Currency/Money