Skip to content

Instantly share code, notes, and snippets.

@elvisgiv
Last active April 27, 2018 13:58
Show Gist options
  • Save elvisgiv/f10e44314831d095e345c726a513757e to your computer and use it in GitHub Desktop.
Save elvisgiv/f10e44314831d095e345c726a513757e to your computer and use it in GitHub Desktop.

in Gamfile

gem "recaptcha", require: "recaptcha/rails"

in controller

use verify_recaptcha(model: @item) method before save changes

  def create
    @item = model.new(contact_params)
    @item.lang = params[:lang]
    #
    @res = verify_recaptcha(model: @item) && @item.save
    respond_to do |format|
      if @res
        format.html {
          redirect_to "/#{params[:lang]}/application/res"
        }
        format.js   {  }
      else
        format.html {
          render :new
        }
      end
    end
  end

in view (form)

= simple_form_for(@item, html: { class: 'form-horizontal' }, url: project_proposals_path) do |f|
  = f.error_notification
  ...
  .captcha
    = recaptcha_tags
  = f.button :submit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment