[英]Using request.referer to redirect
I have two edit pages in my application. 我的应用程序中有两个编辑页面。 After the edits have been saved I want to redirect the user to a different page depending if they are on the '/info' page or '/edit' page.
保存编辑后,我想将用户重定向到其他页面,具体取决于它们是在“/ info”页面还是“/ edit”页面上。 I am trying to use request.referer to find the path the user came from to decide where to redirect them.
我正在尝试使用request.referer来查找用户来自哪里以决定将其重定向的路径。
(If they are on '/info' they came from '/users/sign_up') (如果他们在'/ info'他们来自'/ users / sign_up')
Controller 调节器
if URI(request.referer).path == '/users/sign_up'
redirect_to root_path, notice: "Welcome"
else
redirect_to user_path(@user)
end
The problem is it redirects to user_path regardless of where the user is. 问题是无论用户身在何处,它都会重定向到user_path。
(BTW, i'm not set on using request.referer to solve this. I have also tried using 'current_uri = request.env['PATH_INFO']' with the same luck) (顺便说一下,我没有开始使用request.referer来解决这个问题。我也尝试使用'current_uri = request.env ['PATH_INFO']'同样的运气)
When you are on the /info and then perform edits, you are going to a separate action and another page (the edit page). 当您使用/ info然后执行编辑时,您将进行单独的操作和另一个页面(编辑页面)。 So the referer is going to be the info page not the page before it.
因此,引用者将成为信息页面,而不是之前的页面。 Try:
尝试:
if URI(request.referer).path == '/info'
redirect_to root_path, notice: "Welcome"
else
redirect_to user_path(@user)
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.