javascript 使用 Rails 3.1 资产管道包括外部库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7235307/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Including external libraries using the Rails 3.1 asset pipeline
提问by Alec Wenzowski
Background: I wish to use freebase suggestin my app.
背景:我希望在我的应用程序中使用freebase 建议。
I intend to add an autocomplete to the #location
input using coffeescript:
我打算#location
使用coffeescript为输入添加自动完成功能:
$ ->
$("#location").suggest type: "location"
Which will be included by the asset pipeline at require_tree
in my application.js file:
资产管道将包含require_tree
在我的 application.js 文件中:
//= require jquery
//= require jquery_ujs
//= require modernizr
//= require_tree .
Must I copy suggest.min.js
to app/assets/javascripts
and require it as
我必须复制suggest.min.js
到app/assets/javascripts
并要求它作为
//= require suggest.min
or can I require it directly from its publicly available url?
或者我可以直接从其公开可用的 url 中要求它吗?
回答by cmpolis
You can always get it from the CDN by putting it in a view or template.
您始终可以通过将它放在视图或模板中来从 CDN 中获取它。
<%= javascript_include_tag "http://freebaselibs.com/static/suggest/1.3/suggest.min.js" %>