我在过滤器之前使用这个助手
def has_current_firm
if current_firm.nil?
flash[:warning] = t :error_msg
redirect_to :back
end
end
但是,有时它会潜入无限循环 什么是最简单的方法来确保引用的控制器不等于当前?
答案 0 :(得分:0)
这不是答案,只是一个注释。
Rails 5有redirect_back:
redirect_back fallback_location: { action: "show", id: 5 }
redirect_back fallback_location: post
redirect_back fallback_location: "http://www.rubyonrails.org"
redirect_back fallback_location: "/images/screenshot.jpg"
redirect_back fallback_location: articles_url
redirect_back fallback_location: proc { edit_post_url(@post) }
其来源:
def redirect_back(fallback_location,, **args)
if referer = request.headers["Referer"]
redirect_to referer, **args
else
redirect_to fallback_location, **args
end
end