Rails:如何显示Rails本地项目文件夹中的图像? [英] Rails: How to display image from rails local project folder?

查看:294
本文介绍了Rails:如何显示Rails本地项目文件夹中的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个非常基本的问题,但是不知何故我无法使其正常工作.我试图在项目的本地文件夹中找到一个图像,以显示在Rails上.另外,我正在使用引导程序;因此我也需要声明class: "img-responsive".这是原始代码:<img class="img-responsive" src="assets/img/mockup/img2.jpg" alt="">

A very basic question, but somehow I can't get it to work. I am trying to have an image located in the project's local folder to display on Rails. Additionally, I am using bootstrap; thus I need to declare class: "img-responsive" as well. Here is the original code: <img class="img-responsive" src="assets/img/mockup/img2.jpg" alt="">

我已咨询此帖子,其中建议了<%= image_tag("xyz.png", class: "img-responsive img-thumbnail img-circle") %> ruby​​onrails指南提示image_tag("/icons/icon.gif", class: "menu_icon").

I have consulted this post which suggested <%= image_tag("xyz.png", class: "img-responsive img-thumbnail img-circle") %> and rubyonrails guide which suggested image_tag("/icons/icon.gif", class: "menu_icon").

我尝试过

<%= image_tag ("assets/img/mockup/img2.jpg", class: "img-responsive")%>

<%= image_tag "assets/img/mockup/img2.jpg" %>

但是它仍然不起作用. 我可以确认路径为:app/assets/img/mockup/img2.jpg

But it still does not work. I can confirm that the path is: app/assets/img/mockup/img2.jpg

如何在Rails应用程序视图中显示所述图像?

How can I display the said image on rails app view?

推荐答案

我正在浏览并看到

I was browsing and saw this SO post. I was able to get it work using

<%= image_tag ("/assets/mockup/img2.jpg"), class: "img-responsive"%>

图像路径为assets/images/mockup/img2.jpg;从图像路径assets/mockup/img2.jpg中省略images可以解决此问题.

Image path was assets/images/mockup/img2.jpg; omitting images from the image path assets/mockup/img2.jpg solves the issue.

这篇关于Rails:如何显示Rails本地项目文件夹中的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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