繁体   English   中英

如何设置会话变量以告诉Devise登录或注册后重定向到何处?

[英]How do you set a session variable to tell Devise where to redirect after Sign In or Sign Up?

devise是否具有内置的方法,您可以传递一个包含URL的变量,以便在用户登录或注册后将其重定向到?

谢谢

如果您的模型称为User ,则在config/routes.rb定义一个user_root路由:

match '/profile', :to => "user#profile", :as => "user_root"

然后,Devise将自动将用户重定向到此路径。

Wiki中有一个页面对此进行了解释: https : //github.com/plataformatec/devise/wiki/How-To : -Redirect-to- a-specific-page-on-successful- sign-out-out

application_controller.rb

...
  def after_sign_in_path_for(resource_or_scope)
    example_path
  end

  def after_sign_up_path_for(resource_or_scope)
    example_path
  end
...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM