Created
February 14, 2017 02:36
-
-
Save 3014zhangshuo/b536b1e6bf82a4933d06327d60331433 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module AssetDataBase64Helper | |
def asset_data_base64(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 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment