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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17205085/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 22:12:04  来源:igfitidea点击:

Ruby on Rails displaying image with image_tag src

ruby-on-railsruby-on-rails-3helper

提问by hellomello

I have an image in my app/assets/imagesfolder 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 中加载我的页面时,我的图像仅显示/assets/在其 src 路径中

<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!

谢谢!

回答by prasad.surase

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 和图像资产