views:

1681

answers:

1

I have a rails app that has picked up a bit of traction, but I have a serious headache to deal with. It's a basic sort of asset manager application - users upload their photos, .pdfs, videos, etc., and the system allows them to manage how that asset is presented.

I started with a fairly standard rails view - just what gets generated by rails - for index.html.erb. I have a partial that renders a thumbnail for each of the assets and something like this:

<div id="preview">  </div>

What I want is for the thumbnail to be clickable (easy enough) but when the user hits that button, the contents of the div will be filled with, well, essentially the edit.html.erb, but I'm guessing it needs to be done as a partial. I've already managed this with straight javascript.

I do have access to the pre-publication version of the new 'Agile Development on Rails' book, which anyone can get through the publisher, but the chapter on AJAX is very minimal and assumes more experience with these things than I have, this being my first foray into javascript and rails.

UPDATE: In response to the "what is the question" 'answer', though I thought it was pretty clear:

What do I need to put in the thumbnail's partial to cause a click of it to load the edit form into the div?

+5  A: 

you need to use link_to_remote:

<%=    link_to_remote image_tag('whatever.jpg'), 
       {:controller => 'something', :action => 'replace_thumbnail', :id => @thumbnail.id}, 
       :update => 'preview' %>

and in the controller you should have this action:

def replace_thumbnail
  image = Image.find(params[:id])
  render :partial => 'edit', :object => image, :layout => false
end

make sure your partial is named '_edit.html.erb'

Tilendor