Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
624 views
in Technique[技术] by (71.8m points)

ruby on rails - Sass with erb won't compile

In Rails, file file.css.sass.erb:

.class-name
    width: <%= "10px" %>

Is throwing the error:

Invalid CSS after "": expected expression (e.g. 1px, bold), was "<%= "10px" %>"

Isn't it supposed to work?

Update 1

Still struggling with it, but I found that if I change it to SCSS syntax (filename and code), still it causes a very similar error.

Invalid CSS after " width: ": expected expression (e.g. 1px, bold), was "<%= "10px" %>;"

Although, if I remove the scss extension, leaving the CSS similar syntax with the filename file.css.erb, Rails does compile as expected.

Yet considering I'm forgetting something very obvious, I'm also considering this could be a gem conflict with sass-rails, or a bug, or something. After all, the code is working without SASS extensions.

Update 2

Just found other 4 unanswered questions on this same issue on:

  1. scss.erb ruby code not executing
  2. Assets not being run though the .erb preprocessor
  3. Rails erb preprocessing not happening in development mode
  4. sprockets sass partial erb extension.

Some of them ended up working around the problem by changing approaches. The ERB issue on SASS files remained untouched.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This is indeed a problem with sass-rails, as discussed on GitHub.

So this guy wrote this patch, which completely solves the problem.

The Solution

Add to Gemfile:

gem "sass_rails_patch", "~> 0.0.1"

then run bundle and you're good!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...