images.js.coffee.erb 文件:
<%
imgs = {}
Dir.chdir("#{Rails.root}/app/assets/images/bg/") do
imgs = Dir["**"].inject({}) {|h,f| h.merge! f => image-url(f)}
end
%>
window.image_path = (name) ->
<%= imgs.to_json %>[name]
page.js.coffee 文件:(获取图片路径)
icon=image_path("myfile.jpb")
错误:
undefined local variable or method `image' for #<#<Class:0x007ffdaac7cd88> on line 4
4 imgs = Dir["**"].inject({}) {|h,f| h.merge! f => image-url(f)}
问题是我的 image-url() 方法似乎不起作用。为什么 image_path() 有效,但 image-url 无效?
谢谢你