2

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

1

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

hi thanks for you answer, your'e totally right, but heroku is simply not showing images I call from my images folder
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: stackoverflow.com/questions/18324063/…
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:

  1. In app/images/, you have some image file. For example, linkedin.svg.

Procedure

  1. In your html.erb file, add:

<%= link_to image_tag("linkedin.svg"), "http://www.linkedin.com/in/myprofile",  :target => "_blank"%>
  1. 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.
  2. Check the commas.
  3. Last, just to be safe, make sure your link includes "http://www....."

Comments

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.