草庐IT

ruby-on-rails - Rails 设计 : "You need to sign in or sign up before continuing" instead of "You will receive an email with instructions.."

coder 2025-07-15 原文

我已经安装了 Devise on Rails 4.2.0,一切似乎都在工作,我使用了以下指南:

http://sourcey.com/rails-4-omniauth-using-devise-with-twitter-facebook-and-linkedin/

我的设计模块是:

devise :database_authenticatable, :registerable, :confirmable,
       :recoverable, :rememberable, :trackable, :validatable, :omniauthable

唯一的问题是,如果我尝试通过转到注册页面创建一个新帐户,然后在输入我的电子邮件和新密码(两次)后,我将被带回登录页面并看到“未经身份验证”消息:

 You need to sign in or sign up before continuing

什么时候我应该收到“send_instructions”消息:

 You will receive an email with instructions for how to confirm your email address in a few minutes.

我的 ApplicationController 中有一个 before_filter:

before_filter :authenticate_user!, :except => [:show]

虽然我承认我不明白为什么这不会在登录页面或“忘记密码”页面上给我验证错误。无论哪种方式,我都尝试将 :new_user_session 添加到 :except,但这没有帮助。

当有人注册时,我如何获得正确的闪现通知?

我没有覆盖任何设计代码(源文档建议的除外),我的 DeviseHelper 只有一种打印出闪存消息的方法:

def devise_error_messages!
    return '' if resource.errors.empty?

    messages = resource.errors.full_messages.map { |msg| content_tag(:li, msg) }.join
    messages.html_safe
end

编辑:

我最初搜索 SO 没有帮助(太多不相关的类似问题)但现在我发现了这个:

devise sign_in after sign_out error

所以我认为问题在于 Devise 在我执行 sign_up 操作后试图将我带到我的 root_path。我不知道为什么它会为 :confirmable 设置这样做,它似乎应该带我回到登录页面。

我试图通过在自定义注册 Controller 中覆盖“after_sign_up_path_for”来覆盖它:

Override devise registrations controller

也许我做错了,但这似乎没有帮助。

现在的问题是,我如何让 Devise 在有人注册后返回到登录页面,为什么这不是可确认设置的默认操作?

最佳答案

您提到在自定义注册 Controller 中覆盖 after_sign_up_path_for,但遵循 this link 中的指示,您可能想尝试将其放入您的 application_controller.rb。

关于ruby-on-rails - Rails 设计 : "You need to sign in or sign up before continuing" instead of "You will receive an email with instructions..",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29808241/

有关ruby-on-rails - Rails 设计 : "You need to sign in or sign up before continuing" instead of "You will receive an email with instructions.."的更多相关文章

随机推荐