使用Rails 3.1资产管道的JavaScript代码中的图像的URL? [英] URL of images in JavaScript code using Rails 3.1 asset pipeline?

查看:137
本文介绍了使用Rails 3.1资产管道的JavaScript代码中的图像的URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在CSS文件中,您可以使用以下命令获取图像资源的正确名称(带指纹):

In CSS files, you can get the proper name of an image asset (with the fingerprint) by using:

background-image: url(image-url("rails.png"))

但你怎么做来自JavaScript文件的相同内容?

but how do you do the same from a JavaScript file?

推荐答案

我看到你正在使用sass帮助方法。

I see you are using the sass helper method.

在标准(非Sass)CSS中你可以这样做:

In standard (non Sass) CSS you do something like this:

.class {background-image:url( <%= asset_path'image.png'%>)}

CSS文件需要将erb添加到扩展名中:

The CSS file will need to have erb added to the extensions:

file_name.css.erb

对于javascript适用相同的规则:

For javascript the same rules apply:

file_name.js.erb

并在文件中:

var image_path ='<%= asset_path'image.png'%>'

Rails 资产管道指南是关于如何使用这些功能的极好信息来源。

The Rails asset pipeline guide is an excellent source of information about how to use these features.

这篇关于使用Rails 3.1资产管道的JavaScript代码中的图像的URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆