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
741 views
in Technique[技术] by (71.8m points)

ruby on rails 3.1 - Assets not being run though the .erb preprocessor

I am having trouble trying to rake assets:precompile in my rails 3.1 app. I keep getting the following error:

 rake aborted!
 Invalid CSS after "...und-image: url(": expected ")", was "<%= asset_path(..."

It seems that the erb preprocessor is not being invokeb but my file is called style.css.scss.erb. Any suggestions?

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

Ruby documentation seems a bit unclear on a few things such as the usage of the asset_path and other such helper in stylesheets. Anyways this is what I did to get around the exact same problem:

  1. I decided to do this the SASS-way by changing my stylesheet extensions from css to scss.
  2. The image references in my code were changed from
    background-image: url(<%= asset_path 'blah.png' %>);
    to
    background-image: image-url("blah.png");
I found the necessary documentation on the sass helpers on one of the RailsGuides


I've also added the config.assets.digest = true line to my config/appliction.rb file because that seemed to get my output HTML to refer to the hashed filenames. Without the digest flag set to true I get all of my link tags starting off with
<link href="/assets/print.css?body=1" ... or
<href="/assets/favicon.png"... which pretty much defies the purpose of using the assets pipeline. Especially the favicon file will still be cached by the servers and CDN's along the way.

Explicitely setting the digest flag to true gets me
<link href="/assets/print-e47f5a48af04ce6854c840d74cd28fba.css?body=1" and
<link href="/assets/favicon-15fb5e00d868940bc32db7996e10f594.png" ...


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

...