Recaptcha,Devise和Rails4

时间:2014-05-16 17:37:03

标签: ruby-on-rails-4 devise recaptcha

操作系统:Windows 8.1 Ruby 2.0 Rails 4.1 设计3.xx recaptcha gem

我将recaptcha添加到registrations / new.html.erb视图中:

<%= recaptcha_tags %>

在注册控制器中:

      respond_to do |format|
        unless verify_recaptcha
          format.html { render :new, notice: t('registration_captcha_problem') }
          format.json { render json: @user.errors, status: :unprocessable_entity }
        else
          if @user.save
            format.html { redirect_to root_path, notice: t('registration_successfully_created') }
            format.json { render :show, status: :created, location: @user }
          else
            format.html { render :new }
            format.json { render json: @user.errors, status: :unprocessable_entity }
          end
        end
      end

我还添加了

<%= recaptcha_tags %>

到views / devise / passwords / new.html.erb

这很好用。我尝试测试重置密码链接时遇到问题。应用程序崩溃,并显示以下消息:

undefined method `valid_captcha?' for #<Devise::PasswordsController:0x00000005e421b8>

block (2 levels) in <module:PasswordsControllerCaptcha>
devise_security_extension (0.8.0) lib/devise_security_extension/patches/passwords_controller_captcha.rb

module DeviseSecurityExtension::Patches

  module PasswordsControllerCaptcha

    extend ActiveSupport::Concern

    included do

      define_method :create do

        if valid_captcha? params[:captcha]

          self.resource = resource_class.send_reset_password_instructions(params[resource_name])

          if successfully_sent?(resource)

            respond_with({}, :location => new_session_path(resource_name))

          else

            respond_with(resource)

任何想法如何解决这个问题?我在哪里处理验证码验证的响应?我无法访问该控制器。

0 个答案:

没有答案