Hi! On my page i display one full size image and a list of thumbnails. I'd like to change the full size image with a full size version of a thumbnail, after clicking on one of them. How to write controller action, so it would update the image without reloading the whole page? It's easy with text, but how to reload an image?
on 2006-03-14 17:03
on 2006-03-14 17:22
On Mar 14, 2006, at 17:03, szymek wrote: > On my page i display one full size image and a list of thumbnails. > I'd like to change the full size image with a full size version of a > thumbnail, after clicking on one of them. > > How to write controller action, so it would update the image without > reloading the whole page? It's easy with text, but how to reload an > image? Wrap the full-size image in a div/span with some id to pass to link_to_remote, and let the controller send the full img element with the corresponding src attribute depending on the clicked thumbnail. The browser will show the new image (in my trials). As a design pattern that works for me, to produce the initial page I use the same action in the view via render_component, doing so that part is genereated always in the same way, from a single piece of code. -- fxn
on 2006-03-14 17:28
I didn't suspect it will work but it just did: render :text => "<img src='new_image.jpg' alt='' />"
on 2006-03-14 17:40
Thanks for this render_component tip!
on 2006-03-14 17:50
on 2006-03-16 21:50
Hey thanks! With all that ajax hype i forgot that i can achieve the same without it :) Thanks again!