Open zll11111 opened 5 years ago
你好: 我使用了devise,不想将验证码失败的error放在user里,想将注册时字段错误信息和验证码失败信息分开,所以想调用verify_rucaptcha? nil,如下例子:
class Users::RegistrationsController < Devise::RegistrationsController def create build_resource(sign_up_params) if verify_rucaptcha? resource.save yield resource if block_given? if resource.persisted? if resource.active_for_authentication? set_flash_message! :notice, :signed_up sign_up(resource_name, resource) respond_with resource, location: after_sign_up_path_for(resource) else set_flash_message! :notice, :"signed_up_but_#{resource.inactive_message}" expire_data_after_sign_in! respond_with resource, location: after_inactive_sign_up_path_for(resource) end else clean_up_passwords resource set_minimum_password_length respond_with resource end else #resource.errors.clear flash.now[:alert] = t('rucaptcha.invalid') clean_up_passwords resource respond_with resource end end end
随后看了一下代码,应该是rucaptcha-2.5.0/lib/rucaptcha/controller_helpers.rb里的75行 add_rucaptcha_validation_error方法里resource引用的是全局resource,不是verify_rucaptcha?传进去的resource。
你好: 我使用了devise,不想将验证码失败的error放在user里,想将注册时字段错误信息和验证码失败信息分开,所以想调用verify_rucaptcha? nil,如下例子:
随后看了一下代码,应该是rucaptcha-2.5.0/lib/rucaptcha/controller_helpers.rb里的75行 add_rucaptcha_validation_error方法里resource引用的是全局resource,不是verify_rucaptcha?传进去的resource。