问题描述
我对在 Rails 中将 Galleria 这样的 jQuery 框架放在哪里感到有些困惑3.1的新资产管道?
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
但是,据我所知,Galleria
文件夹使用 jQuery &主题想要在活动站点的根目录 (/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>
编辑:很惊讶没有回应!?!也许Galleria不那么受欢迎?这些是我正在尝试加载的文件.虽然我可以轻松移动它们,但它们是这样捆绑的:
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
我认为 Sprockets require_tree .
会加载 app/assets
、lib/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.
当然,你可以回到旧的做事方式,把所有东西都扔到公共"中,但我们想要自动合并所有 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.
这就是我让它工作的方式:
This is how I got it working:
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.
还有一件事 - 在尝试编译这些资产时,我遇到了一个明显的错误导轨 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 图像库框架)放在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!