在Rails 3.1 Asset Pipeline中将Galleria(jQuery图像画廊框架)放在哪里? [英] Where to put Galleria (jQuery image gallery framework) in Rails 3.1 Asset Pipeline?

查看:110
本文介绍了在Rails 3.1 Asset Pipeline中将Galleria(jQuery图像画廊框架)放在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于在 Rails中将 Galleria 之类的jQuery框架放在何处,我有点困惑3.1 的新 Asset Pipeline ?

I'm a bit confused as to where to put a jQuery framework like Galleria in Rails 3.1's new Asset Pipeline?

从技术上讲,我知道应该进入/vendors/assets/javascripts ,但是,据我了解,带有jQuery&的Galleria文件夹主题希望位于实时站点的根目录(/galleria)中,以便正常工作.

I know it, technically, should go into /vendors/assets/javascripts but, it is my understanding that, the Galleria folder with the jQuery & themes wants to be in root (/galleria) of the live site in order to work correctly.

还有,当我们在下面时,将以下脚本放在哪里,使其仅出现在带有图库的页面上?

Also, while we're at it, where to put the following script so it will appear only on the page(s) with a gallery?

<script>
    $('#gallery').galleria({
        width:500,
        height:500
    });
</script>

编辑:很惊讶没有回应!?!也许环球免税店不那么受欢迎?这些是我要加载的文件.它们像这样捆绑在一起,尽管我可以轻松移动它们:

Edit: Surprised there's no response!?! Maybe Galleria isn't that popular? These are the files I'm trying to load. They are bundled like this though I could easily move them:

vendor/
  assets/
    javascripts/
      galleria-1.2.5.js
      galleria-1.2.5.min.js
    galleria/
      themes/
        classic/
          classic-loader.gif
          classic-map.png
          galleria.classic.css
          galleria.classic.js
          galleria.classic.min.js

我认为链轮 require_tree .会加载app/assetslib/assetsvendor/assets中的所有内容?!?

i thought Sprockets require_tree . would load everything in app/assets, lib/assets and vendor/assets?!?

推荐答案

我遇到了同样的问题,并且花了一些时间才能开始工作.最初,它在开发上可以正常工作,但是当我们投入生产时,Galleria无声地失败了,因为资产文件名现在具有指纹".这似乎也是jQuery UI主题以及许多其他此类脚本的问题.

I had the same problem, and it took a while to get working. Initially, it would work fine on development, but when we moved to production, Galleria silently failed, due to the asset filenames now having "fingerprints". This also seems to be an issue with jQuery UI themes, and many other such scripts.

当然,您可以回到旧的处理方式,然后将所有内容都放入"public"中,但是我们希望自动合并所有css/js文件并以rails的方式进行处理.

Of course, you could just go back to the old way of doing things and throw everything in "public", but we would like the advantage of automatically merging all css/js files, and doing things the rails way.

这就是我的工作方式:

vendor/
  assets/
    images/
      classic-loader.gif
      classic-map.gif
    javascripts/
      galleria-1.2.5.js
      galleria.classic.js
    stylesheets
      galleria.classic.css.scss

galleria.classic.css文件重命名为galleria.classic.css.scss.然后像这样替换图像引用(我有两个):

Rename your galleria.classic.css file to galleria.classic.css.scss. Then replace the image references, like so (I had two):

url("classic-loader.gif")变为image-url("classic-loader.gif")

更新:看起来您不需要在Rails 3.1.1中执行此操作.只需将文件重命名为.css.scss,Rails就会自动为您预处理url()调用.

在您的app/assets/javascripts/application.js文件中,请确保您有行

In your app/assets/javascripts/application.js file, make sure you have the lines

//= require galleria-1.2.5
//= require galleria.classic
//= require_tree .

在您的app/assets/stylesheets/application.css文件中,请确保您有行

In you app/assets/stylesheets/application.css file, make sure you have the lines

*= require galleria.classic
*= require_tree .

最后,Galleria似乎内置了一些奇特的非标准css加载程序.这就是阻止Galleria加载到我们的生产网站上的原因.由于我们已经包含了样式表,因此我们要禁用此行为.只需打开galleria.classic.js(或您的Galleria主题javascript文件),然后替换以下行:

Finally, Galleria seems to have some fancy non-standard css loading built in. This is what was preventing Galleria from loading on our production website. Since we have already included the stylesheet, we want to disable this behavior. Simply open up galleria.classic.js (or your Galleria theme javascript file), and replace the line:

css: 'galleria.classic.css',

具有:

css: false,

这将告诉Galleria不要尝试加载样式表.

This will tell Galleria not to try loading the stylesheet.

另一件事-尝试编译这些资产时,我遇到了一个显然是 Rails 3.1.0 .当我运行rake assets:precompile时,出现类似以下错误:

One more thing - when trying to compile these assets, I ran into what is apparently a bug in Rails 3.1.0. When I ran rake assets:precompile, I got errors like:

$ bundle exec rake assets:precompile
rake aborted!
classic-loader.gif isn't precompiled
  (in /vendor/assets/stylesheets/galleria.classic.css.scss)

长话短说,您需要在config/environments/production.rb中设置此行:

Long story short, you need to set this line in config/environments/production.rb:

config.assets.compile = true

在3.1.1发布后,就不需要此操作了.

This shouldn't be necessary once 3.1.1 is released.

这篇关于在Rails 3.1 Asset Pipeline中将Galleria(jQuery图像画廊框架)放在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆