[英]Rails/Devise How to redirect to a specific page after login
After login
and signup
, I want to redirect the user to a specific page only if the user came from a specific page. login
并signup
,仅当用户来自特定页面时,我才要将用户重定向到特定页面。
What I have tried to do so far – using devise
: 到目前为止,我一直在尝试使用devise
:
I added a parameter to a link and checked that parameter in the login page. 我在链接中添加了一个参数,并在登录页面中检查了该参数。 Using the method after_sign_in_path_for(resource)
from devise
, I created a conditional to that parameter. 使用方法after_sign_in_path_for(resource)
从devise
,我创建了一个有条件的该参数。 If true
, the page would be redirect to my wanted page 如果为true
,则页面将重定向到我的通缉页面
Link 链接
<%= link_to "Login before continuing", new_user_session_path(:registration_process => true)
On ApplicationController.rb
在ApplicationController.rb
def after_sign_in_path_for(resource) if params[:registration_process] leads_path # desired page else super end end
This is not working. 这是行不通的。
I don't know if using params
is the best option, since I want to do the same with the sign up page. 我不知道使用params
是否是最佳选择,因为我想对注册页面执行相同的操作。
Thank you very much. 非常感谢你。 Any help will be much appreciated. 任何帮助都感激不尽。
Easy! 简单! Why not try: 为什么不尝试:
URI(request.referer).path
? URI(request.referer).path
吗?
Now you can basically identify the path where you came from. 现在,您基本上可以确定您的来源了。
You can also store the page where you came from in a session. 您还可以存储会话中您来自的页面。 eg 例如
session[:intended_url] = request.url
hope that helps. 希望能有所帮助。
Try This one 试试这个
if resource.class == User && current_user
user_dashboard_path
else
super
end
我认为您应该在具有new_user_session_path形式的会话中传递带有会话路径的参数,例如url: session_path(resource_name, :registration_process => true)
,然后再使用if params[:registration_process]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.