您可以在ApplicationController中存储多个redirect_to路径...最好使用单独的before_action来执行此操作
before_action :store_back_paths def store_back_paths # if session[:back_path] doesn't exist, create it as an empty array session[:back_path] ||= [] # add the current path as a new entry in the array session[:back_path] << request.referer # while there are more than five entries, drop the oldest entries # this is to ensure we're not storing too many entries session[:back_path].shift while session[:back_path].count > 5 end
进行普通重定向时,请使用pop删除数组中的最后一个元素并返回删除的值。
redirect_to session[:back_path].pop
在销毁后进行重定向时,请删除最后一个条目(指向销毁项目的显示页面),然后重定向到该条目之前的路径。
session[:back_path].pop # drops the last entry redirect_to session[:back_path].pop