# Rendering images through JS in rails

**URL:** <https://www.ruby-forum.com/t/rendering-images-through-js-in-rails/166655>\
**Category:** Rails\
**Created:** [April 28, 2009, 9:32am UTC](https://www.ruby-forum.com/t/rendering-images-through-js-in-rails/166655 "2009-04-28T09:32:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 28, 2009, 9:32am UTC](https://www.ruby-forum.com/t/rendering-images-through-js-in-rails/166655/1 "2009-04-28T09:32:57Z")

</div>

Hi,  
I am newbie to rails.  
I use an jquery ajax function to get some json data  
and have to render an image according to the result.

## say

## HTML:

## JS: if (true){ $(’#status’).html(\<%=IMAGE1%\>); } else{ $(’#status’).html(\<%=IMAGE2%\>); }

I’ve tried a lot of way but couldn’t come to a solution.  
Please help.

Regards,  
Vimal Das

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 28, 2009, 5:13pm UTC](https://www.ruby-forum.com/t/rendering-images-through-js-in-rails/166655/2 "2009-04-28T17:13:29Z")

</div>

On Tue, Apr 28, 2009 at 12:31 AM, vimal [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I use an jquery ajax function to get some json data  
> and have to render an image according to the result.

Not really a Rails question, but…

> JS:  
> if (true){  
> $(‘#status’).html(\<%=IMAGE1%\>);  
> }  
> else{  
> $(‘#status’).html(\<%=IMAGE2%\>);  
> }

? Why don’t you just return the appropriate image tag in your JSON  
response, and insert it, e.g. $(‘#status’).html(new\_image\_tag ?

–  
Hassan S. ------------------------ removed\_email\_address@domain.invalid
