Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用devise,当verify_rucaptcha? 后不跟resource参数时,resource.errors里还是出现error #77

Open
zll11111 opened this issue Apr 4, 2019 · 0 comments

Comments

@zll11111
Copy link

zll11111 commented Apr 4, 2019

你好:
我使用了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

2019-04-04 22-18-07屏幕截图

随后看了一下代码,应该是rucaptcha-2.5.0/lib/rucaptcha/controller_helpers.rb里的75行
add_rucaptcha_validation_error方法里resource引用的是全局resource,不是verify_rucaptcha?传进去的resource。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant