2

所以我的 assets/javascripts 文件夹中有一个文件夹,它运行一个名为 galleryview 的图像幻灯片。在这个文件夹内是一个主题目录,其中包含我的“下一个”和“上一个”按钮的图像,因此......

资产/javascripts/galleryview/主题/

现在运行这个的javascript,通过这个链接到这些图像......

//Determine path between current page and filmstrip images
//Scan script tags and look for path to GalleryView plugin
        $('script').each(function(i){
            var s = $(this);
            if(s.attr('src') && s.attr('src').match(/jquery\.galleryview/)){
                img_path = s.attr('src').split('jquery.galleryview')[0]+'themes/';
            }
        });

但是,我现在在 Rails 应用程序中使用它,所以我需要将此 img_path 行指向

资产/图像/

那么我的 imag_path 现在应该是什么样子?

img_path = ?

这是 jsfiddle 上的整个 javascript 文件代码....将其复制并粘贴到编辑器中,我感兴趣的区域在第 389 行附近。

http://jsfiddle.net/thefonso/Sqmxa/

4

1 回答 1

2

不确定这段代码是否能正常工作,但我认为你可以使用帮助image_path程序让你接近。就像是:

img_path = <%= image_path 'images/'%>;

把它放在一个.js.erb文件中,上面显示的 ERB 应该被解析并输出字符串"/assets/images/",分配img_path给值"/assets/themes/"

当然,你也可以这样做:

img_path = "/assets/images/";

...但我猜,使用帮助程序的好处是,如果“资产”路径发生变化,您无需更新硬编码字符串。

于 2012-09-08T17:48:58.207 回答