【问题标题】:image-url not working图片网址不起作用
【发布时间】:2013-04-06 15:10:37
【问题描述】:

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 无效?

谢谢

【问题讨论】:

  • 你的意思是image_url 可能吗?

标签: ruby-on-rails coffeescript sass


【解决方案1】:

因为方法 image-url 不是 ruby​​ 的有效方法名称。

另外,rails api文档中没有定义,你可以随时查看api documentation reference

尝试在你的irb中做:

def image-url
  puts "Hi"
end

它会说代码无效:)

【讨论】:

  • image-url 似乎在 SASS 中工作,这就是我感到困惑的原因,但无论哪种方式,我都使用了 image_path,它似​​乎工作正常。谢谢
猜你喜欢
  • 2016-03-06
  • 1970-01-01
  • 1970-01-01
  • 2011-07-21
  • 2019-11-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多