如何在Rails中刷新redirect_to:back页面



在订单的索引操作中,我允许用户更改用户每页看到的10个订单中的一个的状态。

当用户单击按钮时,POST请求完成并转到OrdersController#process。当完成后,我做一个redirect_to:back,这样用户就可以看到他在点击按钮之前看到的完全相同的页面(我有分页)。

问题是显示的状态不更新,除非我做刷新。我已经在我的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

但是没有运气,我仍然看到旧的状态信息,除非我刷新页面。

我错过了什么?

redirect_to(:back)将把您移回历史。因此,您必须刷新页面或使用ajax更改状态。或者使用浏览器的localStorage,这样您就不必进行ajax请求了。从本地存储器中读取数据并更改页面上的状态

最新更新