javascript - 预编译 application.js 资源

标签 javascript jquery ruby-on-rails ruby-on-rails-3 ruby-on-rails-4

如何让我的 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/

相关文章:

javascript - 在点击事件之前执行 stringByEvaluatingJavaScriptFromString

javascript - Typescript 使用基本 API 类型断言 API 响应类型

jquery - 第三次克隆后禁用选项卡克隆

javascript - 如何使用 var javascript onchange 事件更新输入类型 ="text"值?

ruby-on-rails - 在 Heroku 上上传网站 : Host key verification failed

Mysql2::错误: 'comments' 中的未知列 'having clause'

javascript - 如何使 $ionic 弹出窗口仅出现一次,然后不再出现?

javascript - 如何检查javascript中的输入值

ruby-on-rails - 如何在 Rails 3 中使用 Draper 装饰嵌套属性(关联)?

javascript - Vanilla JS 动画?