简体   繁体   中英

How to refresh page on redirect_to :back in Rails?

In my index action of Orders, I let the user to change the status of one of the 10 Orders that a user sees per page.

When the user clicks on a button, a POST request is done and goes to OrdersController#process . When that is finished I do a redirect_to :back so the user is able to see the exact same page (I have pagination) that he was seeing before he clicked on the button.

The problem is that the status that is shown is not updated unless I do a refresh. I have tried this in my OrdersController :

before_action :set_cache_buster
def set_cache_buster
  response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate"
  response.headers["Pragma"] = "no-cache"
  response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT"
end

But no luck, I still see the old status message, unless I refresh the page.

What am I missing?

redirect_to(:back) will move you to back in the history. so, you have to refresh the page or just change the status using ajax. Or use localStorage of browser, so you don't have to make a ajax request. Read the data form the local-storage and change the status on the page.

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