help with page.replace_html and partials

Hello,

The gist of this is that I'm trying to move an item from one partial to another, and the item disappear when I delete it from the first partial, and have that item appear in the second partial instantly. Just moving a listing from one partial to another, without rerendering the entire page. Simple, right? Can't figure it out.

I have two partials (lists) on a page (index).

Each partial gets drawn, paginated, from this part of my index controller:

def index

     @listing_pages, @listings = paginate(:listings,          :conditions => ["search_term_id = ? and deleted = '0'", id],         :order => 'position',         :per_page => 50)      @deleted_listing_pages, @deleted_listings = paginate(:listings,          :conditions => ["search_term_id = ? and deleted = '1'", id],         :order => 'updated_at DESC',         :per_page => 5)

end

Both partials work, and paginate correctly. I've put the code for them below.

When I click a button, I want a listing's "deleted" column in the database to update from 0 to 1, then update the _deleted_listings.rhtml partial, so that the "deleted" listings shows up in the "deleted_listings.rhtml" partial.

I have an action in my controller called "update_deleted" that does just this, and it works in the database. I have a partial called update_deleted.rjs that looks like this:

page.replace_html "deleted_web_listing", :partial => "deleted_listings"

And it does not work. Help! I can't figure it out. When I do this:

page.replace_html "deleted_listing", '<div>replacement text</div>'

I see "replacement text" in the right place. But when I put the partial name in there, I get an error that suggests that my partial _deleted_listings.rhtml is not picking up the right parameters to render properly, though it renders fine when called from the page index.rhtml.:

ActionView::TemplateError (You have a nil object when you didn't expect it! You might have expected an instance of Array. The error occurred while evaluating nil.each) on line #2 of app/views/ admin/_deleted_listings.rhtml: 1: <div id="deleted_web_listing" class="left_column_listing"> 2: <% for listing in @deleted_listings %> 3: <div id="deleted_item_<%=listing.id %>" class="box_left"> 4: <div class="x_image"> 5: <%= link_to_remote(image_tag("restore.gif", :size => "44x13", :border => "0" ),

Charlie

_listings.rhtml

<div id="listing" class="listing">   <% for listing in @listings %>   <div id="item_<%= listing.id %>" >     <div id="box" class="box">       <div class="x_image">         <% item = "item_#{listing.id}" %>         <% deleted_item = "listing" %>         <%= link_to_remote(image_tag("x.gif", :size => "17x13", :border => "0" ),     :url => { :action => 'update_deleted' , :id => listing.id},     :before => visual_effect(:fade, "item_#{listing.id}", :duration => "0.5" ),     :complete => visual_effect(:highlight, "deleted_listings_header", :startcolor => "'#FF0000'" )) %>       </div>       <table><tr>       <td>       <div class="search_result_position"><%= listing.position %>.</

</td>

      <td><div class="search_result_title"><%= link_to(truncate(listing.title, 60), {:controller => 'redirect', :action => 'log_and_redirect', :id => listing.id}) %></

</td>

      </tr>       </table>       <div class="search_result_description"><%= h(truncate(listing.description, 90)) %></div>       <div class="search_result_url_to_show"><%= h(truncate(listing.url_to_show, 70)) %></div>     </div>   </div> <% end %> </div>

_deleted_listings.rhtml

<div id="deleted_listing" class="left_column_listing">   <% for listing in @deleted_listings %>     <div id="deleted_item_<%=listing.id %>" class="box_left">       <div class="x_image">       <%= link_to_remote(image_tag("restore.gif", :size => "44x13", :border => "0" ),     :url => { :action => 'restore_deleted' , :controller=> :admin, :id => listing.id})     %>       </div>       <div class="search_result_url_to_show"><%= h(truncate(listing.url_to_show, 22)) %></div>       <div class="search_result_description"><%= h(truncate(listing.description, 35)) %></div>     </div> <% end %> </div>