我正在运行 rails 4.2.5 并且我已经通过 devise/twitter-bootstrap-rails/devise-bootstrap-views 生成了我所有的用户创建页面,然后通过本教程添加了 recaptcha:https : //github.com/ plataformatec/devise/wiki/How-To:-Use-Recaptcha-with-Devise
单击 recaptcha 时,注册过程工作正常,但是当您输入信息但不进行 recaptcha 时,整个页面会重新加载并清除,并且尽管已填写,但仍会引发“电子邮件不能为空”错误。
任何帮助弄清楚如何修复错误处理的帮助将不胜感激。
假设您已经使用了操作方法链接中的代码 - 只需尝试向puts
控制台添加一些日志,看看您得到了什么:
class RegistrationsController < Devise::RegistrationsController
prepend_before_action :check_captcha, only: [:create] # Change this to be any actions you want to protect.
private
def check_captcha
# v---- (1) One log here
puts "Verify recaptcha: #{verify_recaptcha}"
unless verify_recaptcha
# v---- (2) Another one here
puts "Signup params: #{sign_up_params}"
self.resource = resource_class.new sign_up_params
resource.validate # Look for any other validation errors besides Recaptcha
# v---- (3) And one here
puts "Validation errors: #{resource.errors.full_messages}"
respond_with_navigational(resource) { render :new }
end
end
end
希望这会给你足够的信息来解决这个问题。
额外奖励:https : //tenderlovemaking.com/2016/02/05/i-am-a-puts-debuggerer.html是关于如何调试代码并通过使用简单的puts
.
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句