Rails 设计:"You need to sign in or sign up before continuing" 而不是 "You will receive an email with instructions.."

Rails Devise: "You need to sign in or sign up before continuing" instead of "You will receive an email with instructions.."

我在 Rails 4.2.0 上安装了 Devise,一切似乎都正常,我使用了指南:

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

我的设计模块是:

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

唯一的问题是,如果我尝试通过转到注册页面创建一个新帐户,然后在输入我的电子邮件和新密码(两次)后,我将返回登录页面并看到 'unauthenticated' 消息:

 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]

虽然我承认我不明白为什么这不会给我登录页面或 'forgot password' 页面上的身份验证错误。无论哪种方式,我都尝试将 :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

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

我试图通过在自定义注册控制器中覆盖 'after_sign_up_path_for' 来覆盖它:

Override devise registrations controller

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

所以现在的问题是,我如何让 Devise 在有人执行 sign_up 后返回到 sign_in 页面,为什么这不是可确认设置的默认操作?

您提到在自定义注册控制器中覆盖 after_sign_up_path_for,但按照 this link 中的说明,您可能想尝试将其放入 application_controller.rb。