Rails 3.1 样式表中的图像损坏
我一直在运行一个最初在 Rails 3.1.0.rc4 下编写的小应用程序。昨晚我开始过渡到 3.1.0 Final。好吧,我在资产管道中遇到了令人沮丧的障碍。我的js很好,我的css也很好;然而,样式表中包含的图像并不好。我正在使用 .css.scss.erb 扩展,以便我可以使用 SASS 和 asset_path 帮助程序来提供已编译资产的路径。
示例:
background: url(<%= asset_path "background.png" %>);
导致:
background: url('background.png');
这是一个问题,因为编译的资源是 background-a76dde63a16fbb15fe1b4ec496b50877.png
image_tag 和 asset_path 在应用程序的 erb 视图中都能正常工作,但在 scss 文件中却不能。任何意见都将非常受欢迎。
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 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果将
.css
文件更改为.scss
,您可以使用_url
和_path
帮助器 sass-rails 提供:background: image_url("background.png")
将在生产中被拾取并“指纹识别”。更多信息
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