16

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?

0

5 Answers 5

41

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"
Sign up to request clarification or add additional context in comments.

1 Comment

This works, but if there is no dinamic involved, the static version of the tag (like pierr's) shall save you some millisecons on rendering, which of course you only matter if you have millions of visitors and load is an issue.
2

<%= link_to image_tag post.image %>

Comments

1

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

Comments

0

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' %>

Comments

-5

Tested and worked.

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

2 Comments

What was your previous attempt? :-/
Images don't have a closing tag like that... <img />

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.