简体   繁体   English

Rails / Devise登录后如何重定向到特定页面

[英]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. loginsignup ,仅当用户来自特定页面时,我才要将用户重定向到特定页面。

What I have tried to do so far – using devise : 到目前为止,我一直在尝试使用devise

  1. 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.

相关问题 Rails在登录后设计重定向 - Rails Devise redirect after login 使用devise和rails重定向到特定页面3 - redirect to specific page with devise and rails 3 Rails-Devise-登录或注销后重定向到当前页面 - Rails - Devise - Redirect to current page after login or logout 使用devise在Rails 3中发送密码重置说明后,如何将用户重定向到登录页面 - How to redirect the user to login page after sending password reset instructions in rails 3 using devise Rails 和 Devise:成功登录后如何将用户重定向回请求的页面? - Rails and Devise: How to redirect user back to the requested Page after successful login? 用户请求新的确认后如何重定向到设计登录页面 - How to redirect to the Devise login page after user requests new confirmation 如何将使用omniauth(Rails with Devise)注册的用户重定向到特定页面? - How to redirect a user signed up with omniauth (Rails with Devise) to a specific page? 使用Devise登录后重定向到上一页 - Redirect to previous page after login with Devise Rails / Devise /链接到登录页面,并向其传递重定向路由,以在成功登录后使用 - Rails / Devise / Link to login page and pass it a redirect route to use after successful login Rails,Devise:如何在登录时重定向未确认的帐户 - Rails, Devise: How to redirect unconfirmed account on login
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM