Home > Back-end >  How to get only image src attribute from rails image_tag?
How to get only image src attribute from rails image_tag?

Time:11-09

How can I get the image src attribute only from rails image_tag or how can I parse "src" only from the response of image_tag?

ActionController::Base.helpers.image_tag("diane.png")

gives back

<img src=\"/assets/diane-d88012c06a724682b02dfbd9224dbaac15872a3ae649453964f7d5b234021274.png\" alt=\"Diane\" />

But I only need the string in the src attribute.

I have a scenario in which I only need "src" attribute in the rails app generated by image_tag, so JS or Jquery ways of reading the html attribute is not feasible here.

CodePudding user response:

You can use image_path:

 ActionController::Base.helpers.image_path("diane.png") 
  • Related