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.