Created
May 20, 2016 06:45
-
-
Save 2get/2e49cb97f6612a57174de0183a1fed88 to your computer and use it in GitHub Desktop.
Reference Rails asset images in JS
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
<% | |
imgs = {} | |
Dir.chdir("#{Rails.root}/app/assets/images") do | |
imgs = Dir.glob("**/*.{gif,jpg,jpeg,png}").inject({}) { |h, f| h.merge! f => image_path(f) } | |
end | |
%> | |
window.image_path = function(name) { | |
return <%= imgs.to_json %>[name]; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment