validates_captcha not generating a captcha

Newbie here.

This is not a question but a report on a work-around for a problem I detected with the gem validates_captcha.

My environment is Windows, Vista, Rails Rails 2.3.5 Ruby 1.8.6 gem 1.3.5 validates_captcha-0.9.6

The problem: validates_captcha is generating a default gif with the word "captcha" in it rather than a captcha with the value of a a random string (the captcha) in it.

The work-around: In module .\lib\validates_captcha\image_generator\simple.rb there is the following module

- - - - - - - -      def generate(captcha_code)         image_width = captcha_code.length * 20 + 10

        cmd =         cmd << "convert -size #{image_width}x40 xc:grey84 -background grey84 -fill black "

        captcha_code.split(//).each_with_index do |char, i|           cmd << " -pointsize #{rand(8) + 15} "           cmd << " -weight #{rand(2) == 0 ? '4' : '8'}00 "           cmd << " -draw 'text #{5 + 20 * i},#{rand(10) + 20} \"#{char}\"' "         end

        cmd << " -rotate #{rand(2) == 0 ? '-' : ''}5 -fill grey40 "

        captcha_code.size.times do           cmd << " -draw 'line #{rand(image_width)},0 #{rand(image_width)},60' "         end

        cmd << " gif:-"

        image_magick_command = cmd.join

        `#{image_magick_command}`      end - - - - - - - -

The problem appears to be in the line    cmd << " gif:-"

replace this with    cmd << " gif:c:\tmp\SomeTempFile.gif"

and then read (binary) c:\tmp\SomeTempFile.gif and push that string out instead of `#{image_magick_command}` pumping the output to stdout.

SomeTempFile.gif should probably not be a unique name since several users might want to generate captchas at the same time. I keyed my name off of the captcha code but there may be a better way to do this. If anone has a good solution to this, I'd love to hear it.

Oh, do remember to delete the uniquely named file or your tmp directory will fill up quickly.

It works for me. Your mileage may vary.

Ralph Shnelvar wrote:

Newbie here.

This is not a question but a report on a work-around for a problem I detected with the gem validates_captcha.

When you are writing things like this, there is no need to begin your posts with "Newbie here."

Actually, that's probably true in general. If your level of understanding is that if a newbie, it will show in what you write. If it doesn't show in what you write (as here), then you're not in newbie territory. In either case, there is no point to beginning your posts this way. :slight_smile:

Best,