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. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
in destroy method, try a redirect_to(:back) On Mar 13, 7:20 am, Brent Smith <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> 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. > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks a lot, works great! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---