Rails Recaptcha 插件总是返回 false [英] Rails Recaptcha plugin always returns false

查看:69
本文介绍了Rails Recaptcha 插件总是返回 false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此处找到的 rails recaptcha 插件:http://github.com/ambethia/recaptcha/tree/master

I'm using the rails recaptcha plugin found here: http://github.com/ambethia/recaptcha/tree/master

我已在 recaptcha.com 上注册了一个帐户,获得了一个公开的 &私钥,站点配置了全局密钥(暂时).

I have signed up for an account on recaptcha.com, obtained a public & private key, and the site is configured with a global key (for now).

config/environment.rb 中我设置了环境变量:

In config/environment.rb I setup the environment variables:

ENV['RECAPTCHA_PUBLIC_KEY'] = 'xxxxxxxxxxxxxxxx'
ENV['RECAPTCHA_PRIVATE_KEY'] = 'XXXXXXXXXXXXXXxx'

在我看来,我像这样渲染验证码:

In my view I render the captcha like this:

<%= recaptcha_tags %>

在我处理这个表单的控制器中,我有这个:

And in my controller processing this form I have this:

unless verify_recaptcha #   <--  always returns false
    flash[:error] = "Your captcha entry was invalid"
    render :action=>'new'
    return
end

我的问题是 verify_recaptcha 总是 返回 false.

My problem is that verify_recaptcha always returns false.

我一定遗漏了一些简单的东西,但我没有看到.在我收到 smart-alec 回复之前,是的,我正在验证码框中输入正确的单词 :)

I must be missing something simple, but I don't see it. And before I get a smart-alec reply, YES I'm typing the correct words into the captcha box :)

推荐答案

请注意,确保您没有不小心切换了公钥和私钥;它们是不同的.

Just as a note, make sure you didn't accidentally switch around the public and private keys; they are different.

我不知道你是否已经在处理它的可能性,在这种情况下你会想要这样的东西:

I can't tell if you're already handling the possibility that it is correct, in which case you would want to have something like this:

if verify_recaptcha
  @thing.save!
  redirect_to success_path
else
  flash[:error] = "There was an error with the recaptcha code below. Please re-enter the code and click submit." 
  render :action => 'new'
end

记得使用:

<%= recaptcha_tags :ssl => true %>

如果您使用的是 SSL.

If you are using SSL.

这篇关于Rails Recaptcha 插件总是返回 false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆