18

In Rails is there a way to get the URL to the image (going through the assets_host) and just return the URL of the image? I want to use assets_host data in my Javascript, but I just need to insert the URL into the JS, not the whole image_tag.

Thank you in advance!

tesserakt
  • 3,231
  • 4
  • 27
  • 40

1 Answers1

27

image_path will return (you guessed it) the path to the image. It's the same method used in image_tag.

Jordan Running
  • 102,619
  • 17
  • 182
  • 182
  • 1
    for full image url check out http://stackoverflow.com/questions/7597127/rails-3-1-absolute-url-to-an-image – lulalala Jul 18 '12 at 10:27
  • Updated links! Relative path to image: https://api.rubyonrails.org/classes/ActionView/Helpers/AssetUrlHelper.html#method-i-image_path Absolute path: https://api.rubyonrails.org/classes/ActionView/Helpers/AssetUrlHelper.html#method-i-image_url – saudes Jul 20 '22 at 20:33