问题描述
我的/app/assets/images目录中有一个jpg,并通过以下CSS将其用作背景.
I have a jpg in my /app/assets/images directory and am using it as a background with the following CSS.
body {
background-image: image_url('metal_texture.jpg')
}
asset_url帮助器在这种情况下也可以使用.由于Rails 4资产管道不关心文件放置在/app/assets中的哪个目录下,是否有理由使用image_url和asset_url?
The asset_url helper also works in this case. Since the Rails 4 asset pipeline doesn't care which directory in /app/assets that the file is placed, is there a reason to use image_url vs asset_url?
推荐答案
Source code: image_url, asset_url
image_url
实际上调用了 asset_url
并传递了一个特定选项: {type::image}
并且 compute_asset_path 根据该 option [:type]
image_url
actually calls asset_url
passing one specific option: {type: :image}
And compute_asset_path finds asset directory based on that option[:type]
这篇关于sass-rails助手"image_url"之间的区别和"asset_url"在Rails 4.0中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!