1

在我的 Rails 应用程序中,我使用 devise gem 和简单的验证码从这里https://github.com/pludoni/simple-captcha

我想添加此验证码仅用于注册操作,我这样做了,但我是 Rails 新手,不知道 - 我所做的是否好?也许有人可以看看?对于使用这条链的其他人来说,这也是一个很好的“教程”......

所以从 gem doc 中我使用模型变体,我添加了我需要建模的内容,添加到设计允许的参数的验证码和验证码参数,并且在控制器中我有这样的代码:

 def create
    build_resource(sign_up_params)
    if resource.valid_with_captcha?
      resource_saved = resource.save
    end
    yield resource if block_given?
    if resource_saved
      if resource.active_for_authentication?
        set_flash_message :notice, :signed_up if is_flashing_format?
        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}" if is_flashing_format?
        expire_data_after_sign_in!
        respond_with resource, location: after_inactive_sign_up_path_for(resource)
      end
    else
      clean_up_passwords resource
      respond_with resource
    end
  end

我是好是错?如果错了,请帮助以正确的方式做,现在它也可以了......只是我没有这样做是好还是不好......

4

1 回答 1

0

这是自己设计的完整文档。

https://github.com/plataformatec/devise/wiki/How-To:-Use-Recaptcha-with-Devise

于 2014-05-07T18:30:47.443 回答