Undefined method `asset_data_uri '- Rail 3.2

I have a partial person.css.erb:

#caption { background-image: url(<%= asset_data_uri("caption.png") %>); text-align: center; } 

When partial processing is displayed with an error:

 undefined method `asset_data_uri' 

The rails resource pipeline guide has an example of using this method: http://guides.rubyonrails.org/asset_pipeline.html

Such helpers work, for example. asset_path. I am using Rails 3.2.8. Is the manual obsolete? Has the method been renamed? Do I need to do anything special to enable this assistant?

+4
source share
1 answer

I used the same error when using asset_data_uri in my view ( asset_path worked) and could not understand why. This is not exactly your problem, but I was able to fix mine by adding it 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 
+12
source

Source: https://habr.com/ru/post/1439007/


All Articles