6

我已经在 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

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

 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 的搜索没有帮助(太多类似的问题不相关),但现在我发现了这个:

在sign_out错误后设计sign_in

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

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

覆盖设计注册控制器

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

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

4

1 回答 1

1

您提到after_sign_up_path_for了在自定义注册控制器中覆盖,但按照此链接中的指示,您可能想尝试将其放在您的 application_controller.rb 中。

于 2015-04-27T05:28:28.897 回答