AJAX - Image output to an IMG tag?

Hi,

I’m using the “link_to_remote” AJAX function call from my “view”, and
what i want is after i get the results from the function call, I want to
update the result
directly into to an image ie. tag, how to do this.??

ie. if we want to update the result into a ‘div’ element we do like
this, which works fine…
link_to_remote(:update => ‘updatediv’,
:url => { :action => :my_method })

But i want to update the output which is an ‘Image’ in my case into a
HTML IMG tag and display it in the browser. I want to go only for
tag…

Thank You
Dinesh

Guest wrote:

Hi,

I’m using the “link_to_remote” AJAX function call from my “view”, and
what i want is after i get the results from the function call, I want to
update the result
directly into to an image ie. tag, how to do this.??

ie. if we want to update the result into a ‘div’ element we do like
this, which works fine…
link_to_remote(:update => ‘updatediv’,
:url => { :action => :my_method })

But i want to update the output which is an ‘Image’ in my case into a
HTML IMG tag and display it in the browser. I want to go only for
tag…

Thank You
Dinesh

Should be simple enough. You want to use RJS.

First remove the :update part of the link_to_remote.

Then create a view file for your action except call it my_method.rjs
instead of my_method.rhtml.

Now put something like this in my_method.rjs:
page[‘id_of_my_image_element’].src = @image.method_that_returns_src

And you should be set.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs