如何在Rails中显示URL指向的图像

问题描述:

HI,

我这里有一张图片 http://power.itp.ac.cn/~jmyang/funny/fun4.jpg 我希望在我的Rails网站上显示它。我该怎么做?

I have a image here http://power.itp.ac.cn/~jmyang/funny/fun4.jpg and I want to display it in my Rails site. How should i do that?

编辑:嗯,伙计们,我现在明白了这些投票。这是因为它太天真了一个问题:)对不起,在问这个问题之前我几乎不了解HTML标签,但感谢Rails,即使我自己也可以建立一个网站。 Rails rock!

Well, guys , I understand the downvotes now. It is because it is too naive a question:) Sorry, I knew almost nothing about HTML tags before asking the question, but thanks to Rails, even I could build a web site myself. Rails rocks!

您还可以使用操作视图 image_tag helper :

You can also use the action view image_tag helper:

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

或者你可以使用常规的HTML标签:

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" }

超薄:

img src="http://power.itp.ac.cn/~jmyang/funny/fun4.jpg"