views:

43

answers:

1

I'm trying to make an AJAX call in Rails to swap images on a page. The page has a big div that is initially blank, along with a table with several entries. One of the columns in this table contains the path for an image, and what I am trying to do is on user click, swap this image into the div.

I was hoping to have a controller variable hold the path to the current image, and on user click store the new value into the variable, and I guess in the view somehow retrieve this value in an image_tag, but I haven't gotten it to work.

I haven't found any guides on how to do this, any ideas? I'm using prototype because Rails seems to prefer it, which doesn't work well for me because I come from a jQuery background...

A: 

this is a working example http://jsfiddle.net/S44dC/

From.ME.to.YOU
I'm looking for a solution that sends an AJAX request to my Rails controller so that I can do some extra stuff on the back end. Your solution is a nice fallback for me though, thanks =)
Anon
inside the TR click function ... send the data "the image URL" for example with $.ajax call .. while that add a class loading to the div container. and set oncomplete function to the ajax call that will output the image after you got your info from the server
From.ME.to.YOU