1

私のレールアプリでは、devise gemと、ここからのシンプルなキャプチャを使用しています https://github.com/pludoni/simple-captcha

サインアップアクションのためだけにこのキャプチャを追加したいのですが、私はレールに慣れていないので知りませんでした. 多分誰かが見ることができますか?また、これは、このチェーンを使用する他の人々にとって良い「チュートリアル」になります...

したがって、gem doc からモデルバリアントを使用し、モデル化する必要があるものを追加し、許可されたパラメーターの captcha および captcha_key パラメーターを考案し、コントローラーにそのようなコードを持っています。

 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