[英]Rake asset routes for a rails project
I may be wrong here, but routes are automatically generated for files in your public directory. 我在这里可能是错的,但是会自动为您的公共目录中的文件生成路由。
So if this was in your rails project 因此,如果这在您的Rails项目中
public/images/cat.jpg
You could literally type " public/images/cat.jpg " and it would appear in the browser. 您可以直接输入“ public / images / cat.jpg”,它将出现在浏览器中。 Is there anyway to rake routes and get these asset routes? 无论如何,有没有耙路和获得这些资产路线? Or they not actually roots? 还是他们根本不扎根? Do they work differently? 他们的工作方式不同吗?
#{RAILS_ROOT}/images/cat.jpg
这样就可以了。
They are not actually routes, they are considered "static assets" and are simply served up as is. 它们实际上不是路线,它们被认为是“静态资产”,可以按原样使用。
From the Rails asset pipeline documentation : 从Rails 资产管道文档中 :
Any assets under public will be served as static files by the application or web server. 应用程序或Web服务器会将任何公开的资产用作静态文件。
So in the end, there's nothing really special about them; 因此,最后,它们之间没有什么特别的。 they are merely served up. 他们只是服务。 That's about it. 就是这样
Also, the URL www.example.com/public/images/cat.jpg
will not work, you'll need to ditch the public
part, so that it appears like www.example.com/images/cat.jpg
, or simply /images/cat.jpg
if this is a link. 另外,URL www.example.com/public/images/cat.jpg
将不起作用,您需要删除public
部分,以使其看起来像www.example.com/images/cat.jpg
,或者简单地/images/cat.jpg
如果是链接)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.