Created
April 24, 2012 21:14
-
-
Save melvynhills/2483876 to your computer and use it in GitHub Desktop.
Rails image asset paths available in JavaScript
This file contains 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
# Full code at https://gist.github.com/1406349/fa7c357b86790c183f3ef81ad6870b78bb2de343 | |
window.assets = { | |
<% | |
Dir.glob(Rails.root.join("app/assets/images/**/*.*")).map do |path| | |
img_name = path.gsub(Rails.root.join("app/assets/images/").to_s, "") %> | |
"<%= img_name %>": "<%= asset_path(img_name) %>", | |
<% end %> | |
} | |
# Then all images are available as such: window.assets['my_image.jpg'] |
You are right. My mistake.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Doesn't work for me.