Rails 4 - 如何在供应商文件中引用一个javascript源代码 [英] Rails 4 - how to reference a javascript source in vendor file
问题描述
我刚刚发现我需要直接在我的应用程序中插入javascript文件来修改我的GMaps for Rails设置。 Rails 4 - Gmaps4Rails - 地图不会呈现
I have just discovered that I need to amend my GMaps for Rails setup by inserting javascript files directly in my app. Rails 4 - Gmaps4Rails - map won't render
我克隆了信息框和markerclusterer回购站,现在我试图在应用中引用相关文件。
I have cloned both infobox and markerclusterer repos and am now stuck in trying to reference the relevant files in my app.
我拥有我的供应商文件中包含克隆文件的文件夹。
I have the folders of files that came with the clone in my vendor file.
我知道我需要使用的javascript文件是:infobox.js和markerclusterer.js
I understand the javascript files that I need to use are: infobox.js and markerclusterer.js
这些文件位于:
These files are located in:
vendor/js-marker-clusterer/src/makerclusterer.js
vendor/v3-utility-library/src/infobox.js
我想在这个视图中使用它们代替代码:
I want to use them in place of the code in this view:
<script src="//maps.google.com/maps/api/js?v=3.18&sensor=false&client=&key=&libraries=geometry&language=&hl=®ion="></script>
<script src="//google-maps-utility-library-v3.googlecode.com/svn/tags/markerclustererplus/2.0.14/src/markerclusterer_packed.js"></script>
<script src='//google-maps-utility-library-v3.googlecode.com/svn/tags/infobox/1.1.9/src/infobox_packed.js' type='text/javascript'></script> <!-- only if you need custom infoboxes -->
我需要引用app / application.js中的javascript文件吗?如果是这样,我需要在路径的哪一点启动(因为这些文件不在vendor / assets / javascripts文件夹中)?
Do I need to reference the javascript files in app/application.js? If so, at what point in the path do I need to start (given these files are not inside the vendor/assets/javascripts folder)?
另外,我理解我需要以某种方式整合markerclusterer图像。这些也通过了克隆的回购,并存储在vendor / js-markerclusterer / images文件夹中。如何引用这些文件以便它们在视图中工作?
Also, I understand I need to incorporate the markerclusterer images somehow. Those have also come through in the cloned repo and are stored in vendor/js-markerclusterer/images folder. How do I reference these so that they work in the view?
推荐答案
最合理的做法是将文件夹 js-marker-clusterer
和 v3-utility-library
vendor / assets / javascripts
,所以你可以在
application.js
中引用你需要的文件作为
The most logical thing to do would be to place folders js-marker-clusterer
and v3-utility-library
under vendor/assets/javascripts
so you can reference the files you need in application.js
as
//= js-marker-clusterer/src/makerclusterer
//= v3-utility-library/src/infobox
但是,如果由于某种原因无法完成这项工作,您可以将自定义路径添加到 config.assets.paths
中,这样自动加载器可以找到它们
If, however, you cannot do that for some reason you can add a custom path into config.assets.paths
so the autoloader can find them
// application.rb
config.assets.paths << Rails.root.join("vendor", "js-marker-clusterer")
config.assets.paths << Rails.root.join("vendor", "v3-utility-library")
然后参考他们就像
And then reference them just as
//= src/makerclusterer
//= src/infobox
这篇关于Rails 4 - 如何在供应商文件中引用一个javascript源代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!