views:

27

answers:

0

I have a list of Area objects that I'm displaying in a Facebook application. I would like to have a link for editing them, next to each row. I would like the form to appear in a <fb:dialog>, so I created the following partials:

# _edit.fbml.erb
<% fb_dialog("edit_area_#{@area.id}", false) do %>
 <%= fb_dialog_title "Edit area" %>
 <% fb_dialog_content do %>
  <%= render :partial => "form", :locals => {:area => @area} %>
 <% end %>
 <%= fb_dialog_button "submit", "Edit", {:form_id => "area_#{@area.id}_form"} %>
 <%= fb_dialog_button "button", "Cancel", {:close_dialog => true} %>
<% end %>

# _form.fbml.erb
<% semantic_form_for [:admin, area], :html => {:id => "area_{@area.id}_form"} do |form| %>
 <%= form.inputs %>
<% end %>

Facebook dialogs works like this: you put somewhere in the page the <fb:dialog> you may need to pop up, then you make it appear via a <a> tag with a clicktoshowdialog option.

Now, generating an <fb:dialog> for each Area object I'm going to display in the page is very far from optimal, so I think this can be done with an Ajax request (preferably with jQuery), that intercepts the click and produces the right dialog when it is needed. Still I have no idea (and no experience) on how to do this.

Any idea? Thanks.