【问题标题】:How do you Reference Images in JS File when using the Asset Pipeline?使用 Asset Pipeline 时如何引用 JS 文件中的图像?
【发布时间】:2012-05-07 15:36:57
【问题描述】:

我在我的 Rails 3.1 应用程序中使用 jQuery Lightbox。我正在使用资产管道,我想知道处理这些对 .js 文件中的图像的引用的最佳方法是什么:

// jQuery Lightbox Init / settings
// Visit http://leandrovieira.com/projects/jquery/lightbox/ for more options and updates
jQuery("a[href$=.jpg],a[href$=.png],a[href$=.gif]").lightBox({
    imageLoading:   '/images/jquery-lightbox/lightbox-ico-loading.gif', // (string) Path and the name of the loading icon
    imageBtnPrev:   '/images/jquery-lightbox/lightbox-btn-prev.gif',        // (string) Path and the name of the prev button image
    imageBtnNext:   '/images/jquery-lightbox/lightbox-btn-next.gif',        // (string) Path and the name of the next button image
    imageBtnClose:  '/images/jquery-lightbox/lightbox-btn-close.gif',   // (string) Path and the name of the close btn
    imageBlank:     '/images/jquery-lightbox/lightbox-blank.gif'            // (string) Path and the name of a blank image (one pixel)
});

【问题讨论】:

    标签: jquery ruby-on-rails-3 lightbox


    【解决方案1】:

    如果这是一个 js.erb 文件,你可以使用 ruby​​ 和 assets_path 方法:

       imageLoading: "<%= asset_path 'jquery-lightbox/lightbox-ico-loading.gif' %>"
    

    等等

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-25
      • 1970-01-01
      • 1970-01-01
      • 2011-12-18
      • 2012-06-12
      • 2013-10-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多