Rails erb preprocessing not happening in developme

2019-08-20 02:59发布

问题:

For whatever reason, this first attempt at dynamic styling gets me a Sass::SyntaxError on the line below. It looks like the erb is not being pre-processed.

/* app/assets/stylesheets/variables.css.scss.erb */

$headerHeight: <%= '15px' %>;

It's in development mode. Any idea what could cause this?

Here are my configuration options relating to assets in case that helps:

# Application
config.assets.enabled = true
config.assets.initialize_on_precompile = true
config.assets.version = '1.1'

# Development
config.assets.compress = false
config.assets.debug = false

回答1:

The scss needs quotes around the 15px part. So you will need to make it:

$headerHeight: "<%= '15px' %>";


回答2:

This is a sass-rails error, as discussed here.

I had the same question and found out that the solution is by installing sass-rais-path.

This gets Rails to work SASS + ERB as expected. No need to use quotes.