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”, ‘
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
<%= listing.position %>.
|
<%=
link_to(truncate(listing.title, 60), {:controller =>
'redirect', :action => 'log_and_redirect', :id => listing.id}) %> |
_deleted_listings.rhtml