如何在View内部显示私人文件夹中的图像?

编程入门 行业动态 更新时间:2024-10-23 08:39:41
本文介绍了如何在View内部显示私人文件夹中的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要对似乎很简单的内容进行快速提示.我在私人文件夹中有一些图片,想在我的视图"中显示它们.

I need a quick tip on something which seems really simple. I have some pictures inside private folder and would like to display them inside my View.

我发现的唯一解决方案是:

The only solution I found was this:

def show send_file 'some/image/url', :disposition => 'inline', :type => 'image/jpg', :x_sendfile => true end

我已阅读到:disposition => 'inline'不应触发图像下载,并允许我在View中显示它.问题在于,每次触发show操作时,图像下载都会自动激活并自动下载. show操作的视图未显示.

I've read that :disposition => 'inline' should not trigger image download and allow me to display it inside my View. The problem is that each time I trigger show action, image download is automatically activated and it is automatically downloaded. View for show action is not displayed.

如何在视图"中显示该图像?谢谢.

How can I display that image inside my View? Thank you.

推荐答案

我这样做的方式(并不是说这本书很完美)是我为图像创建了根,并在控制器中进行了操作以进行渲染它.

The way I do it, and I'm not saying it's perfectly by the book, is I make a root for images and an action in the controller to render it.

例如,在routes.rb中

So, for instance, in routes.rb

match '/images/:image', to: "your_controller#showpic", via: "get", as: :renderpic

在您的控制器中:

def showpic send_file "some/path/#{params[:image]}.jpg", :disposition => 'inline', :type => 'image/jpg', :x_sendfile => true # .jpg will pass as format end def show end

在您看来

<img src="<%= renderpic_path(your image) %>">

这是一个可行的示例,"send_file"上的参数较少

Here is a working example, with fewer parameters on "send_file"

def showpic photopath = "images/users/#{params[:image]}.jpg" send_file "#{photopath}", :disposition => 'inline' end

更多推荐

如何在View内部显示私人文件夹中的图像?

本文发布于:2023-11-02 08:21:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1551875.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图像   私人   文件   夹中   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!