I have a partial "person.css.erb":
#caption {
background-image: url(<%= asset_data_uri("caption.png") %>);
text-align: center;
}
When the partial is rendered it fails with:
undefined method `asset_data_uri'
The rails asset pipeline guide has an example of using this method: http://guides.rubyonrails.org/asset_pipeline.html
Similar helpers work, eg. asset_path. I'm using Rails 3.2.8. Is the guide outdated? Was the method renamed? Do I need to do something special to get this helper included?
I was running into the same error when using asset_data_uri
in my view (asset_path
worked) and couldn't figure out why. This isn't exactly your issue, but I was able to fix mine by adding this to my application_helper.rb
:
# Copied from Sprockets::Context.asset_data_uri, and slightly modified.
def asset_data_uri path
asset = Rails.application.assets.find_asset path
throw "Could not find asset '#{path}'" if asset.nil?
base64 = Base64.encode64(asset.to_s).gsub(/\s+/, "")
"data:#{asset.content_type};base64,#{Rack::Utils.escape(base64)}"
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With