在公共文件夹中显示静态图像(rails 4) [英] Display static image in public folder (rails 4)
问题描述
我在公共文件夹中有一些图像,我在控制器中获取了 url /public/link/to/image.jpg
.我想在我的视图中显示它,所以我将 url 传递给视图.
I have some images in the public folder, I obtain the url /public/link/to/image.jpg
in my controller. I want to display it in my view, so I passed the url to the view.
但是我怎样才能在网页上显示它呢?
But how can I display it on the webpage?
我搜索了帖子,大部分都与assets文件夹中存储的照片有关,可以通过<%= image_tag image-url (filename) %>
in view 来检索.
I searched through the post, most of them related to photos stored in assets folder,
whichi can be retrieved by <%= image_tag image-url (filename) %>
in view.
那么我怎样才能在视图中显示公共文件夹中的图像?
So how could I display image in public folder in view?
推荐答案
我刚刚在我的一个应用程序中对此进行了测试,将图像添加到公共文件夹中,并且能够使用以下方法将其呈现在视图中:
I just tested this out in one of my applications, adding an image to the public folder, and was able to render it in view by using:
我以前从未通过公共文件夹完成过,但如果我不得不猜测,我会说您不需要文件路径的/public"部分.
I've never done it through the public folder before, but if I had to guess I'd say you don't need the "/public" part of the file path.
如果我理解了这个问题,那就应该这样做 - 希望有所帮助.
If I understand the question, that should do it - hope to have helped.
这篇关于在公共文件夹中显示静态图像(rails 4)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!