服务静态资产(例如.jpg等)的途径 [英] A route to serve static assets (like .jpgs, etc?)

查看:55
本文介绍了服务静态资产(例如.jpg等)的途径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经解决了许多有趣的路由问题-将请求URL转换为哈希等,但是出于好奇,有一种方法可以告诉路由系统您想要任何东西从字面上提供服务的某个网址子路径-无需通过控制器?

I've worked my way through a number of interesting routing problems - turning a request URL into a hash, etc., but just out of curiosity, is there a way to tell the routing system that you want anything that comes under a certain url subpath to be served literally - without going through a controller?

例如,如果我有/home/me/public_html/rails_proj/images/foo.jpg和... / rails_proj / images / other / bar.jpg ,我是否可以插入一条路线,说图像下的任何内容都应作为默认mime类型的对象使用?

For instance, if I have /home/me/public_html/rails_proj/images/foo.jpg, and .../rails_proj/images/other/bar.jpg, can I insert a route that says "anything under images should just be served as an object of the default mime type?"

可能很有趣。

推荐答案

如果将 images目录放入Rails应用程序的 public文件夹中(例如:/ public / images /),则您除非您的Web服务器配置错误,否则MIME类型应该不会有任何问题。

If you put the "images" directory into the "public" folder of the Rails app (for example: /public/images/) then you shouldn't have any problems with MIME types unless your web server is configured wrongly.

根据您的示例,您希望将图像目录放在应用程序的根目录中。我认为,尽管Rails没有办法使这些图像可见,但是如果您确实想要,可以使用mod_rewrite使它起作用。再次由Web服务器来确保图像具有正确的MIME类型。

According to your examples, you want the images dir in the root of the app. I don't think there is a way though Rails to make those images visible, but if you really wanted to you could use mod_rewrite to make it work. Once again, it would be up to the web server to make sure the images had the correct MIME type.

这篇关于服务静态资产(例如.jpg等)的途径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆