Q:

Change image_tag file-name with Javascript dynamically

I always end up writing sth like this in my code:
function setSomeImage(image_name) {
$("#some_div").html("<%= image_tag ('image.png') %>");
}

I am setting images based on a variable that I pass and I have to use the image_tag helper to write it properly in rails. However, Javascript and the image_tag don't work together very well.
What I want to do is, I want to manipulate the image_tag filename dynamically with javascript.
I can now write sth like this:
function setSomeImage(image_name) {
$("#some_div").html('<img src="/assets/'+image_name+'.png">');
}

but that is not clean.
I want to use the image_tag helper, sth like this:
function setSomeImage(image_name) {
$("#some_div").html('<%= image_tag ('+image_name+') %>');
}

but that's not working.
Any idea how I could combine both? Is there any best practice doing this?
Another idea is to pass the image_path directly as a variable to the function but that is not always possible.

A:

If your js file has extension of js.erb, you'll be able to use asset_path helper to display some asset but you won't be able to pass a js variable to it because first ruby part will be evaluated and during that time image_name, a js variable won't be present.

