登录后重定向到特定 URL [英] Redirect to specific URL after logging in

查看:27
本文介绍了登录后重定向到特定 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Devise 1.0(Rails 2.3 的库)中有没有办法在登录后重定向到特定的 URL 而不是 root_url?

Is there a way in Devise 1.0, the library for Rails 2.3, to redirect to a specific URL and not root_url after logging in?

忘记提及它是设计 1.0

推荐答案

您的用户可能在 after_sign_in_path 被调用之前被重定向.如果用户尝试直接访问受身份验证保护的页面,则会发生这种情况.如果您的 root_path ('/') 受到身份验证保护,这将一直发生.

Chances are that your user is being redirected before after_sign_in_path is called. This happens if the user tries to go to a page that is protected by authentication directly. This will happen all the time if you have your root_path ('/') protected by authentication.

在 google 群组上有关于此主题的讨论:

There's a discussion on google groups about this topic:

快速而肮脏的解决方案是覆盖 stored_location_for 以始终返回 nil,如下所示:

The quick and dirty solution is to overwrite stored_location_for to always return nil like so:

class ApplicationController < ActionController::Base  
...

  private 
  def stored_location_for(resource_or_scope)
    nil
  end

  def after_sign_in_path_for(resource_or_scope)
    my_favorite_path
  end
end

这篇关于登录后重定向到特定 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆