所以我有一个应用程序在生产,我有一个评级系统与不同的明星形象,用户可以点击评级电影。在Rails上为JavaScript中的图像使用资产管道?
现在的图像无法正常在浏览器中加载时,我检查元素,它看起来是这样的:
<img src="/assets/star-off.png" alt="1" title="not rated yet">
但图像本身不显示,当我在它悬停,它说:“失败以加载给定的网址我不确定图片是否应该上传到S3或发生了什么..有网站上的其他图像有类似的视图路径,加载就好..
以下是代码星形图像存储在哪里(star-off.png,star-half.png等)
个资产/ JavaScript的/ rateit.js.erb
$.fn.raty.defaults = {
cancel : false,
cancelHint : 'cancel this rating!',
cancelOff : 'cancel-off.png',
cancelOn : 'cancel-on.png',
cancelPlace : 'left',
click : undefined,
half : false,
halfShow : true,
hints : ['bad', 'poor', 'regular', 'good', 'gorgeous'],
iconRange : undefined,
mouseover : undefined,
noRatedMsg : 'not rated yet',
number : 5,
path : 'img/',
precision : false,
round : { down: .25, full: .6, up: .76 },
readOnly : false,
score : undefined,
scoreName : 'score',
single : false,
size : 16,
space : true,
starHalf : 'star-half.png',
starOff : 'star-off.png',
starOn : 'star-on.png',
target : undefined,
targetFormat : '{score}',
targetKeep : false,
targetText : '',
targetType : 'hint',
width : undefined
};
现在
如果我把它放在一个资产路径,如:
starHalf : <% asset_path('star-half.png') %>,
starOff : <% asset_path('star-off.png') %>,
starOn : <% asset_path('star-on.png') %>,
在浏览器这个返回此:
<img src="/assets//assets/star-off-8fc67a767a197757fa4b6033012cd122.png" alt="1" title="not rated yet"> with (failed to load the given url when I hover over the broken image)
我如何得到这个工作?我甚至试过<%image_tag('star-half.png')%>没有运气。
请帮忙!
地段上SO信息的.. http://stackoverflow.com/questions/7381041/url-of-images-in-javascript-code-using-rails-3- 1-asset-pipeline/7383571#7383571 – Upperstage
感谢上级,我确信会这样做,我遵循这些交互并将asset_path存储在var中。但它仍然返回相同的路径与资产// assets/star-off ..等.. – user3399101
更改您的问题的标题,包括RoR和资产预编译,并删除jQuery - 也许比我更有经验的RoR开发人员将回答。我使用上面的链接在我的JS和CSS中使用asset_path。 – Upperstage