Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/457.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何编写Rails 4.2 js资产路径_Javascript_Ruby On Rails 4_Asset Pipeline - Fatal编程技术网

Javascript 如何编写Rails 4.2 js资产路径

Javascript 如何编写Rails 4.2 js资产路径,javascript,ruby-on-rails-4,asset-pipeline,Javascript,Ruby On Rails 4,Asset Pipeline,在供应商目录中的.js文件中有: arrowpointers:{ downarrow: ["img/arrow-down.png", 11,7], //[path_to_down_arrow, arrowwidth, arrowheight] rightarrow: ["img/arrow-right.png", 12,12], //[path_to_right_arrow, arrowwidth, arrowheight] showarrow: {toplevel: t

在供应商目录中的.js文件中有:

arrowpointers:{
    downarrow: ["img/arrow-down.png", 11,7], //[path_to_down_arrow, arrowwidth, arrowheight]
    rightarrow: ["img/arrow-right.png", 12,12], //[path_to_right_arrow, arrowwidth, arrowheight]
    showarrow: {toplevel: true, sublevel: true} //Show arrow images on top level items and sub level items, respectively?
   },

我无法让
箭头down.png
箭头right.png
显示。我尝试了资产和图像路径、url等的所有组合。所有图像都在
app/assets/images
文件夹中。其他所有图像都可以正常工作,但我无法理解。有什么想法吗?

将文件扩展名更改为
js.erb
,这样我们就可以在其中嵌入ruby代码。 将图像添加到
app/assets/images
文件夹中。 然后在
application.rb
中添加此行以启用资产

class Application < Rails::Application
 #add this line
 config.assets.precompile += %w( *.js *.css *.png *.jpg *.jpeg )
end

你说的我都做了。它不起作用。这些箭头图像不会显示。它在rails控制台中显示了什么错误消息?您是否将图像放置在
app/assets/images
文件夹中?如何在控制台中看到该错误?我并没有在控制台中发现错误的经验。好的,你们可以在firefox或chrome中打开控制台,检查是否有关于找不到图像的错误消息显示。要检查rails控制台中的错误,请转到服务器运行的终端窗口,检查是否存在任何404问题,说明未找到arrow-down.png图像。另外,当网页被加载时,它会在页面源代码中的js中显示什么来代替ruby代码。
arrowpointers:{
    downarrow: ['<%= asset_path("arrow-down.png") %>', 11,7], //[path_to_down_arrow, arrowwidth, arrowheight]
    rightarrow: ['<%= asset_path("arrow-right.png") %>', 12,12], //[path_to_right_arrow, arrowwidth, arrowheight]
    showarrow: {toplevel: true, sublevel: true} //Show arrow images on top level items and sub level items, respectively?
   },