Forum: Ruby on Rails reCAPTCHA headache

Posted by Eric J Gruber (Guest)
on 2010-02-08 01:48
(Received via mailing list)
I'm trying to use this (http://ambethia.com/recaptcha/) reCAPTCHA
plugin and have almost got it working. Help me get the last part? I
can't seem to find anything in the logs that indicate an error.

Here is my code. Everything is working good except that part where the
code that's typed is actually validated. Instead, it keeps kicking
back an error. Everything appears to be installed correctly, since the
reCAPTCHA box is showing up; it's just not letting my form save even
though the words are typed correctly.

new.html.erb:
...
<%= recaptcha_tags %>
  <br />
  <%= f.submit 'Submit Your Job' %>
<% end %>

jobs_controller.rb:
def create
    @job = Job.new(params[:job])

    respond_to do |format|
        if verify_recaptcha
      @job.save
        flash[:notice] = 'You job listing was successfully created.'
        format.html { redirect_to(@job) }
        format.xml  { render :xml => @job, :status
=> :created, :location => @job }
      else
        flash[:notice] = 'There was an error with the reCAPTCHA,
please
try again.'
        format.html { render :action => "new" }
        format.xml  { render :xml => @job.errors, :status
=> :unprocessable_entity }
      end
    end
  end

Thanx in advance,

Eric
Posted by Sean Six (seansix)
on 2010-02-08 05:08
Is it throwing some kind of rails error or is the reCAPTCHA not 
accepting a correct answer?
Posted by Sean Six (seansix)
on 2010-02-08 05:26
You may want to try this one as an alternative:

http://expressica.com/simple_captcha/
Posted by Eric J Gruber (Guest)
on 2010-02-08 05:28
(Received via mailing list)
Hi Sean, thanks for writing.

The only error I get is that the words typed were incorrect and that I
need to try again. But the words are correct; it's not accepting the
words that are typed.

Eric
Posted by Eric J. Gruber (Guest)
on 2010-02-08 05:38
(Received via mailing list)
That doesn't look bad, but I'd love to find something that doesn't use
RMagick.
Posted by Sean Six (seansix)
on 2010-02-08 06:17
It must be something related to your installation of the plugin.  It is 
hard to say with the available information you provided what is going 
on.  Have you properly installed the keys?  Here is an application that 
uses recaptcha.  You can use it as a reference I suppose.

http://www.opensourcerails.com/projects/282124-Rails-Dev-Directory
Posted by Kyle (Guest)
on 2010-02-09 01:02
(Received via mailing list)
Eric,

I have it going using the validation syntax recommended in the RDoc:

if verify_recaptcha(:model => @job) && @job.save
...

When I tried using an if/else for the validation, a mismatch threw an
error.

-Kyle
Posted by Kyle (Guest)
on 2010-02-09 14:52
(Received via mailing list)
Upon closer inspection, it was discovered that reCAPTCHA information
was not being submitted with the form.  Form elements were aligned in
a table (I know, I know...but it usually works so well...).  Removing
the table caused reCAPTCHA information to be submitted with the rest
of the form.  There must be a reference that the iframe couldn't make
when it was wrapped in its own <td> tags.

-Kyle
Posted by Marnen Laibow-Koser (marnen)
on 2010-02-09 14:57
Kyle wrote:
> Upon closer inspection, it was discovered that reCAPTCHA information
> was not being submitted with the form.  Form elements were aligned in
> a table (I know, I know...but it usually works so well...).  

And now the lecture: don't use tables for alignment under any 
circumstances.  They are *only* for tabular data.  Break this rule at 
your peril.  Instead of being apologetic, just *don't do* things you 
want to apologize for.

> Removing
> the table caused reCAPTCHA information to be submitted with the rest
> of the form.  There must be a reference that the iframe couldn't make
> when it was wrapped in its own <td> tags.
> 
> -Kyle

Best,
-- 
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.