1

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')
}

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?

darkmoves
  • 328
  • 3
  • 12

2 Answers2

6

Source code: image_url, asset_url

image_url actually calls asset_url passing one specific option: {type: :image} And compute_asset_path finds asset directory based on that option[:type]

Ivan Denysov
  • 1,502
  • 12
  • 16
1

Currently, there is no difference between image-url and asset-url (underscored in Ruby, hyphenated in Sass).

image-url calls asset-url method specifying {type: image}

You can use the asset-url when you don't know the kind of asset.

Edgar Ortega
  • 1,672
  • 18
  • 22