我有一个问题,我正在使用这个插件jQuery Raty(评级系统),我在我的资产/图像文件夹上有星图,但由于某种原因,图像没有显示。知道可能是什么吗?
我已经运行了 rails assets:precompile
因为我在这里找到了这个答案,但没有骰子。
它在localhost上工作正常,这就是路径:
<script>
$('.review-rating').raty({
readOnly: true,
score: function(){
return $(this).attr('data-score');
},
path: '/assets'
});
</script>
<script>
$('.average-review-rating').raty({
readOnly: true,
path: '/assets',
score: function(){
return $(this).attr('data-score');
}
});
</script>
答案 0 :(得分:0)
当您运行命令 assets:precompile 时,将编译所有资产并使用MD5哈希返回文件名之后:
#=> app/assets/images/one-star.png
$ rake assets:precompile
#=> public/assets/one-star-{MD5 Hash here}.png
这就是为什么当您希望星形图片网址看起来像 your-domain.com/assets/one-star.png 时那么它根本无效
从您的代码段中,我认为您正在使用jQuery Raty进行评分,因此解决方案是让Raty通过使用其配置+ Rails资产助手了解您编译的星形图像
<!-- in your view.html.erb file -->
<script>
$('.review-rating').raty({
readOnly: true,
score: function(){
return $(this).attr('data-score');
},
starOn: <%= "#{image_path('star-on.png')}" %>,
starOff: <%= "#{image_path('star-off.png')}" %>,
// Do the same with starHalf, cancelOn, cancelOff
});
</script>
通过这种方式,您的Raty将知道加载星形图像的正确方法。