Rails设计:"您需要在继续之前登录或注册"而不是"您将收到一封包含说明的电子邮件......"

Dav*_*lar 6 ruby ruby-on-rails confirmation-email email-confirmation devise

我已经设置了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
Run Code Online (Sandbox Code Playgroud)

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

 You need to sign in or sign up before continuing
Run Code Online (Sandbox Code Playgroud)

相反,我应该得到'send_instructions'消息:

 You will receive an email with instructions for how to confirm your email address in a few minutes.
Run Code Online (Sandbox Code Playgroud)

我的ApplicationController中有一个before_filter:

before_filter :authenticate_user!, :except => [:show]
Run Code Online (Sandbox Code Playgroud)

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

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

我没有覆盖任何设计代码(除了sourcey doc建议的内容),我的DeviseHelper只有一个打印出flash消息的方法:

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
Run Code Online (Sandbox Code Playgroud)

编辑:

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

在sign_out错误后设计sign_in

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

我尝试通过使用以下命令覆盖cutom注册控制器中的'after_sign_up_path_for'来覆盖它:

覆盖设计注册控制器

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

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

小智 1

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