使用jquery验证recaptcha gem rails

时间:2013-08-13 15:34:56

标签: jquery ruby-on-rails recaptcha

我渲染部分联系表单,我正在使用recaptcha gem。如何使用jquery验证recaptca?

表单代码为:

.content
  .contact
    %b
      %form#new_contact.new_contact{:action => "/contact", :method => "post"}
        = text_field_tag "user_info[name]", nil, placeholder: "Your Name", required: ""
        %br
        = text_field_tag "user_info[email]", nil, placeholder: "Your Email Address", type: "email", required: ""
        %br
        = text_field_tag "user_info[subject]", nil, placeholder: "Subject", required: ""
        %br
        = text_area_tag "user_info[message]", nil, placeholder: "Write your message here", required: ""
        =recaptcha_tags(display: {theme: 'clean'}, ajax: true)
        %button.btn.btn-primary.btn-large{type: 'submit'} Send

控制器代码是:

def contact
    if verify_recaptcha(:model => @user, :message => "Oh! It's error with reCAPTCHA!")
      if Email.contactowner(params[:user_info]).deliver
        flash[:notice] = "Your message has been sent!"
      else
        flash[:notice] = "Your message has not being sent"
      end
      redirect_to request.referrer
    else
      redirect_to request.referrer
      flash[:notice] = 'The captcha that was entered is incorrect, please try again.'
      end
  end

0 个答案:

没有答案