Why might my RoR Ambethia Recaptcha plugin/gem be returning only false?
I'm trying to set up Recaptcha in my Ruby-on-Rails app (Rails 3), using Ambethia's plugin or gem. After I install the plugin or gem and set up my public and private keys in a config/initializers/recap开发者_运维百科tcha.rb, I use it like this:
show view where my form is displayed
<%=raw recaptcha_tags %>
controller where I need to check the recaptcha
if verify_recaptcha && @question.save
...
else
flash[:error] = "Incorrect word verification. Are you sure you're human?"
redirect_to :back
end
No matter what, 'verify_recaptcha' returns false and so the form posting doesn't succeed.
check out this Rails 3 example:
https://github.com/tilo/mail_form_example_with_recaptcha
Just found the answer for my problem. I got wrong recaptcha because of timeout. In verify.rb there is a block where posting to API is proceeding, and it is depending on timeout, that can be set in params of verify() call. And I think that my inet is too slow that's why 3 wasn't enough. I called verify(:timeout => 50) and it worked perfectly.
精彩评论