How can I change the source of the image_tag helper using JQuery?

I am using the Image_tag helper and the asset pipeline from rails, this way:

<%= image_tag "win_jorge_start_0.jpg", :id => "image0" %>

      

I am trying to change the source of image_tag using JQuery like this:

$('#image0').attr( "src" , "win_jorge_complete_0.jpg" );

      

The src of the image changes as expected:

<img alt="Win jorge start 0" src="win_jorge_complete_0.jpg" id="image0">

      

but the source path is not complete as when using the Image_tag helper:

<img alt="Win jorge start 0" src="/assets/win_jorge_start_0-51b6339e1e0a021aa878ee8b54cb957a.jpg" id="image0">

      

Is there a way to do this?

+3


source to share


1 answer


In your JavaScript usage:

$('#image0').attr( "src" , "<%= image_path "win_jorge_start_0.jpg", :id => "image0" %>" );

      



also see AssetUrlHelper # image_path

+2


source







All Articles