开发者

How to display image pointed by URL in Rails

I have a image here http://power.itp.ac.cn/~jmyang/funny/fun4.jpg an开发者_StackOverflow中文版d I want to display it in my Rails site. How should i do that?


You can also use the action view image_tag helper:

<%= image_tag 'http://power.itp.ac.cn/~jmyang/funny/fun4.jpg' %>

Alternatively you can just use the regular HTML tags:

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"


<%= link_to image_tag post.image %>


Put the URL into an img tag inside the view for the page that should display the image.


In my case, the image didn't show until I added alt attribute. So if that didn't work I think you can try this way.

<%= image_tag 'http://power.itp.ac.cn/~jmyang/funny/fun4.jpg', alt: 'fun' %>


Tested and worked.

<img src="http://power.itp.ac.cn/~jmyang/funny/fun4.jpg", width="500" , height="400"> </img>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜