Ruby-on-rails 如何在Rails中显示由URL指向的图像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2582950/
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
How to display image pointed by URL in Rails
提问by pierrotlefou
I have a image here http://power.itp.ac.cn/~jmyang/funny/fun4.jpgand I want to display it in my Rails site. How should i do that?
我在这里有一张图片http://power.itp.ac.cn/~jmyang/funny/fun4.jpg我想在我的 Rails 站点中显示它。我该怎么做?
回答by Kevin Sylvestre
You can also use the action view image_taghelper:
您还可以使用操作视图image_tag助手:
<%= image_tag 'http://power.itp.ac.cn/~jmyang/funny/fun4.jpg' %>
Alternatively you can just use the regular HTML tags:
或者,您可以只使用常规的 HTML 标签:
ERB:
再培训局:
<img src="http://power.itp.ac.cn/~jmyang/funny/fun4.jpg">
Haml:
哈尔:
%img{ src: "http://power.itp.ac.cn/~jmyang/funny/fun4.jpg" }
Slim:
苗条的:
img src="http://power.itp.ac.cn/~jmyang/funny/fun4.jpg"
回答by Albert ventura
<%= link_to image_tag post.image %>
<%= link_to image_tag post.image %>
回答by the Tin Man
Put the URL into an img tag inside the view for the page that should display the image.
将 URL 放入应显示图像的页面视图内的 img 标记中。
回答by pierrotlefou
Tested and worked.
测试和工作。
<img src="http://power.itp.ac.cn/~jmyang/funny/fun4.jpg", width="500" , height="400"> </img>

