简体   繁体   English

Ruby on Rails 显示带有 image_tag src 的图像

[英]Ruby on Rails displaying image with image_tag src

I have an image in my app/assets/images folder and I'm in my view page trying to display an image.我的app/assets/images文件夹中有一个图像,我在我的视图页面中试图显示一个图像。

<%= image_tag "NoAvatar.png" %>

When I load my page in localhost my image only shows /assets/ in its src path当我在 localhost 中加载我的页面时,我的图像仅在其 src 路径中显示/assets/

<img alt="Assets" src="/assets/">

I'm not understanding why this is the issue?我不明白为什么会出现这个问题? Am I doing something wrong?我做错了什么吗? I thought this was how its supposed to link to an image in your pipeline?我认为这是它应该如何链接到您管道中的图像?

Thanks!谢谢!

rails 3.1 n later have a new feature called 'asset pipeline', u can read it at http://guides.rubyonrails.org/asset_pipeline.html rails 3.1 n 以后有一个名为“资产管道”的新功能,您可以在http://guides.rubyonrails.org/asset_pipeline.html阅读它

u can access the image in the view as你可以在视图中访问图像

= image_tag "/assets/large/icon.png"

the image 'icon.png' resides in 'large' under 'images' in 'assets'图像“icon.png”位于“资产”中“图像”下的“大”中

to see how to refer the same image in css, see Rails 3.1 and Image Assets要查看如何在 css 中引用相同的图像,请参阅Rails 3.1 和图像资产

如果您的图像在资产中,请使用:

<%= image_tag("entretien.jpg", width: 200) %>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM