渲染文件 Rails3

发布于 2024-09-13 13:38:41 字数 339 浏览 12 评论 0原文

我正在尝试在 Rails3 的控制器中渲染 png 文件。我正在使用:

render :file=>'public/images/filename.png'

但是,输出似乎不是 PNG 文件(其内容以“PNG”开头 - 用curl 检查它 - 但它不是有效文件)。我在 Rails3 中找不到有关 render :file 的文档。语法为此改变了吗?即使这是 MIME 类型问题,我想我应该能够使用curl 获取该文件。

当使用 Fleximage 的图像(如果可用)时,我使用此技术来显示默认图像。 Fleximage 的图像可以正常工作,但这个简单的操作却不能正常工作。

I'm trying to render a png file in a controller in Rails3. I'm using:

render :file=>'public/images/filename.png'

However, the output seems not to be a PNG file (its contents start with "PNG" -checked it with curl- but it's not a valid file). I cannot find documentation on render :file in Rails3. Has the syntax changed for this? Even if it's a MIME type issue, I think I should be able to obtain the file with curl.

I'm using this technique to show a default image when using Fleximage's images if available. Fleximage's images work correctly, but this simple operation does not.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

初吻给了烟 2024-09-20 13:38:41

使用:

send_file path_to_file

use:

send_file path_to_file
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文