Delete, redirect back to same page

Hello everyone, I’m a beginner at Ruby and Rails, forgive me if this is
a ridiculously easy question, but…

I’m using Rails 2.0 and WillPaginate to paginate a list of products.
Currently when I delete a product, it redirects back to the “Index”,
page 1. What I would like to do is, after destroy is called, redirect
back to the page you were last on. This would be helpful in the case
where you see a list of a bunch of records on, say, Page 4 that you
would like to delete. (rather than clicking Delete, redirect to page 1,
go to page 4, delete, redirect to page 1, go to page 4, delete, etc…)

At first I was thinking about passing the page number though the link_to
in the view somehow, like

<%= link_to ‘delete’, purchased_product, :confirm => ‘Are you sure?’,
:page => @current_page, :method => :delete %> (I know this doesn’t
work)

But, thinking about it, even if I passed the parameter, destroy doesn’t
want any page params, since the “destroy” url is just something like
…/products/5. I don’t want to add a “page” parameter in this part, I
want to add it in the redirect which takes place after the delete takes
place.

def destroy

respond_to do |format|
format.html { redirect_to(products_url+"?page=#{page_number}") }

Is the session the only way to save and access this page parameter? Or
is it OK to pass the page number as a parameter in the link_to? Or is
there an entirely different way that is best?

Any advice would be appreciated, thank you.

in destroy method, try a redirect_to(:back)

On Mar 13, 7:20 am, Brent S. [email protected]

Thanks a lot, works great!