How to repaginate in an AJAX response?

I have a page that shows a collection of objects using ‘paginate’, so
I’m only displaying a subset of the collection on any page. I have a
link_to_remote that calls the “destroy” action. then, within that
action, I render a partial, hoping to display the remaining objects on
that page. The problem is, I’m not sure how to figure out which objects
those are. How do i set :collection to know which objects to pass back
if i don’t know which page i’m on? I thought that perhaps I could figure
it out from request.env[‘HTTP_REFERER’], but there’s no referer in the
request because it’s an AJAX request. Any hints? Or do I have to get up
on pagination?


look at rails ajax scaffold generator. Just use the scaffold generator
to make a simple page and then look at the code. it’s quite easy to
figure out how it works when you can look at it. but it pretty hard to
explain. but I try.

You’ll need something like a container (i.e. a table) which contains
all rows and only this container gets updated after an ajax request.
that means you will have an action which gets the current page from
pagination and render the container with this data. This will work
pretty good, but the bad thing about is, your going to send a lot of
unchanged data to the browser (i.e your pagination value is 10 and
your going to update one row, it will send 9 unchanged rows, too). So
you probably want to send as less data as possible. So you need to know
what has changed or which object has been destroyed. and then you will
update or remove the certain html parts of that object (i.e row in a
table). That means you will have to name each html object like
id=‘container-row-<%= "primarykey of the row "%>’, you can make a
helper for this. with that you have a relation between your data and
the right part of the page.

I hope that will help you to get a little further

thanks for your response- looks like the ajax generator is using RJS
templates, which I wasn’t using. I can look into them, but I was hoping
for something that would integrate into what I have already. Thanks,
though, if there’s nothing else, I’ll check them out.