如何让我的 application.js 中的代码正常工作,以便我可以预编译此处使用的图像?我应该使用什么 Rails 助手?
$(document).ready(function(){
$(".imgthumb").click(function(){
$(".thumbnailcurrent").addClass("thumbnails");
$(".thumbnails").removeClass("thumbnailcurrent");
$(this).addClass("thumbnailcurrent");
$(this).removeClass("thumbnails");
var img=($(this).attr("data-id"));
if (img==1) {
$('.imgbig').html("<%= asset_path src: 'flappy1.jpg', height: '275', width: '391' %>");
} else if (img==2) {
$('.imgbig').html("<%= asset_path src: 'flappy2.jpg', height: '275', width: '391' %>");
} else if (img==3) {
$('.imgbig').html("<%= asset_path src: 'flappy3.jpg', height: '275', width: '391' %>");
}
});
});
最佳答案
预编译的图像位于公共(public)/ Assets 路径中?为什么不直接使用这个路径呢?
关于javascript - 预编译 application.js 资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22264137/