Rails 3.1:无法从vendor/assets目录正确提供javascripts吗? [英] Rails 3.1: javascripts not served correctly from vendor/assets directory?
问题描述
我将javascript文件整理在几个目录中,并且发现了以下奇怪的行为.给出以下树:
+ app
+ assets
+ javascripts
+ common
+ public
+ common
+ home
- home.js
home.js
看起来像这样:
//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require_directory ../../jquery_plugins
//= require_directory ../../common
//= require_directory ../common
//= require_self
现在,技巧就在jquery_plugins
目录中.我将其放置在vendor/assets/javascripts
(检查Rails.application.config.assets.paths
时包含在资产加载路径中)内.当我这样做时,我得到错误:require_tree argument must be a directory
.当我将该目录移到app/assets/javascripts
时,一切正常.
有人知道我在做什么错吗?还是这是一个错误?
您可以使用以下方法将清单文件添加到要提供服务的目录中
vendor/assets/javascripts/jquery_plugins/manifest.js
//= require_directory .
,并通过
在您的app/assets/javascripts/application.js
中要求它
//= require jquery_plugins/manifest
编辑(甚至更简单的方式)
感谢@LeEnno
实际上,您可以将所有与单个库相关的文件放在以库命名的文件夹中,例如vendor/assets/javascripts/bootstrap
,然后在同一文件夹中添加index.js
作为清单,Rails会自动将其提取>
如果在您的
app/assets/javascripts/application.js
您添加行
//= require bootstrap
太容易了!!!
链接到 Rails资产管道指南
I have organized my javascript files in a couple of directories and I have found the following strange behavior. Given the following tree:
+ app
+ assets
+ javascripts
+ common
+ public
+ common
+ home
- home.js
home.js
looks like this:
//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require_directory ../../jquery_plugins
//= require_directory ../../common
//= require_directory ../common
//= require_self
Now the trick lies in the jquery_plugins
directory. I placed this inside vendor/assets/javascripts
(which is included in the asset load path, when I check Rails.application.config.assets.paths
). When I do this I get the error: require_tree argument must be a directory
. When I move that directory to app/assets/javascripts
then everything works.
Does anybody have a clue as to what I'm doing wrong? Or is this a bug?
You could add a manifest file to the directory you are trying to serve with something like
vendor/assets/javascripts/jquery_plugins/manifest.js
//= require_directory .
and require it in your app/assets/javascripts/application.js
via
//= require jquery_plugins/manifest
Edit (even simpler way)
Thanks to @LeEnno for this
You can actually put all your single library related files in a folder named after the library for example vendor/assets/javascripts/bootstrap
and in that same folder add an index.js
which will act as your manifest and Rails will automatically pick it up
if in your
app/assets/javascripts/application.js
you add the line
//= require bootstrap
SO EASY!!!
Link to Rails Asset Pipeline Guide
这篇关于Rails 3.1:无法从vendor/assets目录正确提供javascripts吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!