class Sprockets::Context
def asset_data_uri(path)
$('').attr('src', '<%= asset_data_uri 'avatar.jpg' %>')
#logo { background: url(<%= asset_data_uri 'logo.png' %>) }
Use `asset_data_uri` from ERB with CSS or JavaScript assets:
of the current file.
asset at the specified path, and marks that path as a dependency
Returns a Base64-encoded `data:` URI with the contents of the
def asset_data_uri(path) asset = depend_on_asset(path) data = EncodingUtils.base64(asset.source) "data:#{asset.content_type};base64,#{Rack::Utils.escape(data)}" end