开发者

Rails 3.1 Images Broken in Stylesheets

开发者 https://www.devze.com 2023-04-03 07:35 出处:网络
I\'ve been running a small application that I originally wrote under Rails 3.1.0.rc4. Last night I began the transition to 3.1.0 final. Well I hit a frustrating snag in the asset pipeline. My js is fi

I've been running a small application that I originally wrote under Rails 3.1.0.rc4. Last night I began the transition to 3.1.0 final. Well I hit a frustrating snag in the asset pipeline. My js is fine, my css is fine; however, images included on stylesheets are NOT fine. I'm using .css.scss.erb extensions开发者_StackOverflow so that I can use both SASS and the asset_path helper to provide paths to my compiled assets.

example:

background: url(<%= asset_path "background.png" %>);

results in:

background: url('background.png');

which is a problem since the compiled asset is background-a76dde63a16fbb15fe1b4ec496b50877.png

Both image_tag and asset_path work correctly in erb views in the application, but not in the scss files. Any input would be very welcome.


If you change your .css file to .scss you can use the _url and _path helpers that sass-rails provides:

background: image_url("background.png") will get picked up and "fingerprinted" in production.

More Info


Can't say I've used that helper, but I generally just hardcode

url(/assets/image.jpg);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号