1

I'm currently working on a simple Rails 4 app where I need to fetch an image from a different source and displays it using image_tag.

image_tag('http://blah.com/image.gif')

Looks straightforward, but the http://blah.com/image.gif is secured via simple HTTP Authentication.

enter image description here

Any ideas how to get around with this?

Thanks!

Ben
  • 1,370
  • 17
  • 42
  • 1
    See this question: http://stackoverflow.com/questions/2716990/http-basic-authentication-credentials-passed-in-url-and-encryption – Mike Firesheets Dec 12 '14 at 01:24
  • @MikeFiresheets, it works fine but when you inspect the `src` of the image tag, it shows the user and password which is not good. – Ben Dec 12 '14 at 02:17
  • 1
    If you only need a few images like this & they're going to be static, I'd just download them and add them to your app's assets folder…that's the *easiest* way. If for some reason you must hit the url every time, my guess is you'll need to write your own helper that pulls the credentials from config, visits the url and downloads the image to /tmp or something. I'll write up an answer with example in the morning. – Mike Firesheets Dec 12 '14 at 05:25

1 Answers1

0

Not sure how the server is implemented but you can try

image_tag("http://USERNAME:PASSWORD@blah.com/image.gif")
Byron Singh
  • 1,408
  • 1
  • 13
  • 15