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”, ‘

replacement text

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:


2: <% for listing in @deleted_listings %>
3:

4:

5: <%= link_to_remote(image_tag(“restore.gif”, :size =>
“44x13”, :border => “0” ),

Charlie

_listings.rhtml

<% for listing in @listings %>
<% 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'" )) %>
<%= listing.position %>.
<%= link_to(truncate(listing.title, 60), {:controller => 'redirect', :action => 'log_and_redirect', :id => listing.id}) %>
<%= h(truncate(listing.description, 90)) %>
<%= h(truncate(listing.url_to_show, 70)) %>
<% end %>

_deleted_listings.rhtml

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

[email protected] wrote:

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”, ‘

replacement text

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.:

Is there perhaps a :before_filter that sets up one or more of the
globals the partial is using that does not fire in the ajax stuff when
the deletion fires the rjs?

Maybe “logger.info” all of the globals the partial uses and see what’s
not there?

hth,
jp