gpt4 book ai didi

ruby-on-rails - 登录后重定向到特定 URL

转载 作者:行者123 更新时间:2023-12-04 01:35:44 26 4
gpt4 key购买 nike

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

编辑:忘了提到它是设计 1.0

最佳答案

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

有一个关于这个话题的关于谷歌组的讨论:

  • http://groups.google.com/group/plataformatec-devise/browse_thread/thread/454c7ea651601a6c/64f0adc3be8036d0?#64f0adc3be8036d0

  • 快速而肮脏的解决方案是覆盖 stored_location_for永远返回 nil像这样:
    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

    关于ruby-on-rails - 登录后重定向到特定 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3636112/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com