How can I call an image of some url external website using image_tag in a rails html view? Please, I'm looking for an alternative using image_tag not the regular html or css
Asked
Active
Viewed 4,034 times
2
-
I think this is a duplicate. http://stackoverflow.com/questions/2582950/how-to-display-image-pointed-by-url-in-rails – Stephen Mar 24 '15 at 03:18
2 Answers
1
EDIT Turns out OP wanted to do this b/c Heroku wasn't pulling in images from the assets folder. It is an issue that is easily resolved by reading/following the instructions here: Rails 4 images not loading on heroku .
Leaving the original answer here as it more correctly answers the original question.
image_tag
works with full urls. So you could just give it the URL to the site you want to pull from. i.e:
<%= image_tag 'https://placekitten.com/800/400' %>
I'm sure you are already aware of this, but in 99.999% of situations, hot-linking images from other sites is a very bad idea.

Community
- 1
- 1

aspencer8111
- 786
- 4
- 9
-
hi thanks for you answer, your'e totally right, but heroku is simply not showing images I call from my images folder – saeta Mar 24 '15 at 03:26
-
AH! that is a different issue all together. It is a bit complicated (heroku vs the asset pipeline), but the fix is easy. Just add this to your gemfile: ```rails_12factor```. Here is a better SO question/answer to walk you through it all: http://stackoverflow.com/questions/18324063/rails-4-images-not-loading-on-heroku – aspencer8111 Mar 24 '15 at 13:25
0
Say you have an SVG file that is the image and it points to your Github or Linkedin profile, you could do something like this:
Setup:
- In app/images/, you have some image file. For example, linkedin.svg.
Procedure
- In your html.erb file, add:
<%= link_to image_tag("linkedin.svg"), "http://www.linkedin.com/in/myprofile", :target => "_blank"%>
- Wait!!!!! READ CAREFULLY Pay close attention to the space between image_tag and the parentheses(the method and the argument). Some examples that you'll find online show a space between the image_tag and the argument. Keep them together.
- Check the commas.
- Last, just to be safe, make sure your link includes
"http://www....."

Cronwel
- 103
- 2
- 6