简体   繁体   English

如何在 rails 中拥有 js 和 css 文件以外的资产

[英]how to have assets other than js and css files in rails

I have some object files which I want to have them in my JS codes I put them under app/assets/3d-models and when I try to get a link to it I use:我有一些目标文件,我想将它们放在我的 JS 代码中,我将它们放在app/assets/3d-models ,当我尝试获取它的链接时,我使用:

<%= asset_path("3d-models/splits2/xxx.obj") %>

But the output is /3d-models/splits2/xxx.obj which obviously the 404 NOT FOUND is the result(ie the asset not found, the wrong link!)但输出是/3d-models/splits2/xxx.obj显然404 NOT FOUND是结果(即未找到资产,错误链接!)

Question:题:

How can I get an access link to a file other than common files used in rails' assets?我如何获取到 Rails 资产中使用的常见文件以外的文件的访问链接?

You can have different assets.您可以拥有不同的资产。 Just place them into assets folder and link to them correctly.只需将它们放入资产文件夹并正确链接到它们即可。

Rails are using assets pipeline . Rails 正在使用资产管道 This is a concept, which provides a better way to serve some static files to a website.这是一个概念,它提供了一种更好的方式来为网站提供一些静态文件。 In Rails it is implemented by Sprockets gem .在 Rails 中,它由Sprockets gem实现。 Please read more here .在此处阅读更多内容。

You can also have other static files directly in public folder and link to those files anywhere from your app.您还可以将其他静态文件直接放在公共文件夹中,并从您的应用程序的任何位置链接到这些文件。 This will not be included in assets pipeline.这不会包含在资产管道中。

If you use assets_path helper method, then there is a fingerprint added to a file so the URL to the file is different then.如果您使用assets_path辅助方法,那么文件中会添加一个指纹,因此该文件的 URL 是不同的。

Please check this section .请检查此部分

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM