# Help with page.replace\_html and partials

**URL:** <https://www.ruby-forum.com/t/help-with-page-replace-html-and-partials/106067>\
**Category:** Rails\
**Created:** [June 6, 2007, 3:55am UTC](https://www.ruby-forum.com/t/help-with-page-replace-html-and-partials/106067 "2007-06-06T03:55:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 6, 2007, 3:55am UTC](https://www.ruby-forum.com/t/help-with-page-replace-html-and-partials/106067/1 "2007-06-06T03:55:50Z")

</div>

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 %\>

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 6, 2007, 4:18am UTC](https://www.ruby-forum.com/t/help-with-page-replace-html-and-partials/106067/2 "2007-06-06T04:18:08Z")

</div>

removed\_email\_address@domain.invalid 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
