rails redirect_to :back 不起作用 [英] rails redirect_to :back not working
本文介绍了rails redirect_to :back 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用以下内容:
I'm trying to use the following:
class PaymentsController < ApplicationController
def addproduct
(session[:products] ||= []) << params[:item]
redirect_to :back
end
end
我遇到了这个异常:
undefined method `back_url' for #<PaymentsController:0x007ff682c467a8>
为什么会这样?
推荐答案
Rails 5 具有 redirect_back
,而不是 redirect_to :back
.当请求的 HTTP_REFERER
不存在时,它被更改为用于引发异常.
Rails 5 has redirect_back
, instead of redirect_to :back
. It was changed as it used to raise an exception when request's HTTP_REFERER
was not present.
所以用这个:
redirect_back fallback_location: root_path
您可以根据需要将 root_path
更改为其他内容.
You can change root_path
to something else as per your requirements.
这篇关于rails redirect_to :back 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文