Last active
November 24, 2015 02:18
-
-
Save hyoshida/b5d429558316723d1675 to your computer and use it in GitHub Desktop.
Referencing Rails Assets in CoffeeScript
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
# refs: http://dennisreimann.de/blog/referencing-rails-assets-in-coffeescript/ | |
<% | |
image_path_map = {} | |
Dir.chdir("#{Rails.root}/app/assets/images/") do | |
image_path_map = Dir.glob('**/*').inject({}) do |result, filepath| | |
next result if File::ftype(filepath) == 'directory' | |
result.merge(filepath => image_path(filepath)) | |
end | |
end | |
%> | |
window.image_path = (name) -> | |
image_path = <%= image_path_map.to_json %>[name] | |
image_path ? name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
production 環境で利用する場合は、下記の理由から
rake assets:precompile
を2回実行する必要あり。rake assets:precompile
を実行するrake assets:precompile
を実行する