简体   繁体   中英

How to redirect to the current tab and a specific kaminari page?

I have a destroy method from which when I destroy a product I want to get redirected to the current tab and the number of page that I'm currently on. I'm using the kaminari gem for the pagination part and I'm saving both the name of the current tab and the current number of the page inside cookies. So if I try the following I do get redirected to the current tab I'm on:

redirect_to "#{account_path(current_user.account)}#{cookies[:tab]}"}

But if I try something like the following in order to redirect to the current tab along with the current number of page, it redirects me to the current tab and the first page instead of the current page. I have no idea why this is happening, since both the cookies values are saved correctly:

redirect_to "#{account_path(current_user.account, page: cookies[:page])}#{cookies[:tab]}"}

This is the destroy method I have:

def destroy
  @product.destroy
  respond_to do |format|
    flash[:success] = "Product was successfully deleted"
    format.html { redirect_to "#{account_path(current_user.account, page: cookies[:page])}#{cookies[:tab]}"}
    format.json { head :no_content }
  end
end

Any idea on how I can redirect to the current tab and the current number of page??

Double check that cookies[:page] has the correct value and that show action is accepting the page param.

You might also want to try redirect_to :back or using request.referer , but I'm not sure those preserve the querystring and anchor parts of the URL.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM