Ruby-on-rails 如何在 Rails 4 中加载供应商资产文件夹?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25983283/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 23:55:51  来源:igfitidea点击:

How to load vendor asset folder in Rails 4?

ruby-on-railspluginsruby-on-rails-plugins

提问by ahnbizcad

I have a plugin with many types of files, and its own tree structure (html, css, js, documentation, images, etc)

我有一个包含多种类型文件的插件,以及它自己的树结构(html、css、js、文档、图像等)

Rather than going through the plugin folder, and splitting all the css and js files into the vendor/assets/js/vendor/assets/css/folders, I want to just keep the entire plugin folder as is. For example,

vendor/assets/js/vendor/assets/css/我不想浏览插件文件夹,并将所有 css 和 js 文件拆分到文件夹中,而是希望将整个插件文件夹保持原样。例如,

vendor/assets/multipurpose_bookshelf_slider/

vendor/assets/multipurpose_bookshelf_slider/

How do I make sure the paths load properly, and reference them in my manifest files?

如何确保路径正确加载,并在我的清单文件中引用它们?

Currently, I have some files place as follows (not exhaustive)

目前,我有一些文件如下(并非详尽无遗)

/my_app/vendor/assets/multipurpose_bookshelf_slider/css/skin01.css
/my_app/vendor/assets/multipurpose_bookshelf_slider/js/jquery.easing.1.3.js
/my_app/vendor/assets/multipurpose_bookshelf_slider/
/my_app/vendor/assets/multipurpose_bookshelf_slider/

I'm referencing them in

我在引用它们

application.js

application.js

//= require multipurpose_bookshelf_slider/js/jquery.easing.1.3.js
//= require multipurpose_bookshelf_slider/js/jquery.bookshelfslider.min.js

application.css.scss

application.css.scss

@import "css/bookshelf_slider";
@import "css/skin01";

回答by ahnbizcad

Any folder created directly under assetswill be added to the load paths. Files in that folder can be referenced as usual like so:

直接在其下创建的任何文件夹assets都将添加到加载路径中。可以像往常一样引用该文件夹中的文件,如下所示:

If you have

如果你有

  • vendor/assets/custom/js/file.js

  • vendor/assets/custom/css/file.css

  • vendor/assets/custom/js/file.js

  • vendor/assets/custom/css/file.css

then vendor/assets/custom/will be added to the load paths.

然后vendor/assets/custom/将被添加到负载路径。

Include your files in the following files by doing the following:

通过执行以下操作,将您的文件包含在以下文件中:

application.js

应用程序.js

//= require js/file

//= require js/file

application.css.scss

应用程序.css.scss

@import "css/file";

@import "css/file";

Once that's done, make sure to restart your local server, since it is upon starting your server that the load paths get recognized.

完成后,请确保重新启动本地服务器,因为在启动服务器时,负载路径会被识别。

Note: to see a list of load paths, type in your terminal rails c, then type Rails.application.config.assets.paths.

注意:要查看加载路径列表,请输入您的终端rails c,然后输入Rails.application.config.assets.paths.

回答by D7na

If the application you're running has the assets-pipeline activated, it should find your assets after expanding the path in your application.rb

如果您正在运行的应用程序激活了 assets-pipeline,它应该在扩展 application.rb 中的路径后找到您的资产

config.assets.paths << Rails.root.join("multipurpose_bookshelf_slider")

回答by Ayman Salah

I prefer D7na's answer but with a bit of improvement in my opinion.

我更喜欢 D7na 的答案,但我认为有一些改进。

As long as this is related to assets, I think it is better to be placed in the assets.rbfile.

只要这个和资产有关,我觉得还是放在assets.rb文件里比较好。

assets.rb:

assets.rb

Rails.application.config.assets.paths << Rails.root.join("multipurpose_bookshelf_slider")