e x p r e s s i c a

ruby on rails, business and technicalities

No public Twitter messages.

  • RSS
  • Facebook
  • Twitter
  • Linkedin

Simple Captcha 1.0

Update: SimpleCaptcha 1.2.2 is up!!

Major Changes…

FileSystem Usage Removed

Works Perfectly with Multiple Clustered Servers

Read Here for more details on implementation, usage and examples.


160 Responses so far.

  1. George says:

    Hi sur,
    thanks a lot for this great and simple plugin. update_attribute is working fine.
    And the distortion feature is very useful and was really required.

    Thanks

  2. Jon says:

    The download has vanished??????

  3. Jon says:

    Appeared again, thanks.

  4. Jon says:

    Now i get the following error:

    Permission denied – script/../config/../tmp/simple_captcha/data

  5. sur says:

    give the permissions to this directory so that ruby process can write into it.
    use chmod 777 tmp/simple_captcha/data

    and restart the server. I hope it will work.

  6. Jon says:

    That fixed it, many thanks.

  7. Noah Stern says:

    Thanks for a simple, elegant & excellent solution.

    I had one problem getting it working under Windows XP which is that it didn’t like the font. It couldn’t find it on my box. This was easily remedied by changing the font to arial
    on line 43 of simple_captcha_image.rb.

    Other than that, it worked like a charm.

  8. sur says:

    Hi Noah,

    Previously also it was a problem in the previous version, with one of the user that font was not available on his linux machine too, then in this version i have changed the font-family to ‘courier’ that supposed to be available on every machine, still it is giving u an error!! strange..
    anyhow, u got it working, thats good. I will think of some more generalized solution for this problem.

    Thanks.

  9. TomekF says:

    Hi I followed your instruction, installed plugin and tried to use controller-based version
    but got error when trying to dispaly in the view

    undefined local variable or method `show_simple_captcha’ for #:0x3b01b38>

    I have no clue what could be the reason ? can you give me some clue maybe ??

  10. sur says:

    Hi Tomekf,
    what i can guess is you might have not restarted your server.
    Just make sure that you can see the installed plugin as vendor/plugins/simple_captcha, restart your server and try if it is working!

    Thanks.

  11. Hugo says:

    Installed the plugin and received the following error message when I try to start the server:
    => Booting WEBrick…
    /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.1/lib/commands/servers/
    webrick.rb:11: warning: already initialized constant OPTIONS

    I’m using rails 1.2.3

  12. sur says:

    Hi Hugo,
    are you sure that the application is working fine without the SimpleCaptcha, because i am not using any constant named OPTIONS in the plugin.
    Try staring your application by removing the plugin, we will see if problem is actually because of SimpleCaptcha.

    Thanks.

  13. Devon says:

    I got the same error as Dennis, I also delete the plugin and check out again. but I still got the error.

    unable to read font `n022003l.pfb’

    I use ruby ruby 1.8.5, rails 1.2.3 on Vista.

    Any ideas?

  14. Devon says:

    I change self.font_family to other fonts, it works now.

    self.font_family = ‘Gisha’

  15. Devon says:

    self.font_family = ‘Courier New’ also works. I check the windows/fonts directory, there’s no font named ‘courier’ (I cannot find this font name in Word).

    If someone got this error(unable to read font `n022003l.pfb’), Just change the self.font_family , I think it works.

  16. Sur says:

    Hi Devon,

    can you try one thing….
    Just remove/comment the line self.font_family at all from the code, i wanna see whether it will take the default font in Vista too or not.

    Thanks.

  17. baur says:

    i can’t checkout svn repo

    at windows tortouseSVN it gives
    Error: Unknown hostname ‘rubyforge.org’

    at web-server linux FC3
    [root@air813 dump]# svn co svn://rubyforge.org/var/svn/expressica/plugins/simple_captcha simple_captcha
    Segmentation fault

    but i play nice with repo started with http://

    please help me

  18. sur says:

    Hi Baur,
    I have just tried it again on WIN-XP, Tortoise SVN is checking it out properly here… anyhow.

    DOWNLOAD it directly…

    Thanks

  19. baur says:

    Thanks Sur.
    Great work you done.

    Rails User Group / Kazakhstan / Shymkent city

  20. sur says:

    Hi Baur,
    glad to know that u like it.

    Thanks

  21. james says:

    Have you ever tested this plugin on a MAC? I’m getting similar problems with the fonts RMagick is trying to load – but can’t seem to resolve it…

  22. sur says:

    Hi James,
    can you try it…
    check out the latest code from the repository or download the archive and just remove/comment line # 43 that is self.font_family = ‘courier’ of the file vendor/plugins/simple_captcha/lib/simple_captcha_image.rb, then restart the server and test it, it should take the default font from the machine the. I hope it should work

    Thanks.

  23. Nannakey says:

    I am also getting the same error as Hugo.

    Without this plugin the application works fine.
    I updated my InstantRails to the latest version 1.7 using Rails 1.2.3

    In earlier version of InstantRails (Rails 1.6.6) it worked just fine.
    I am using Windows XP Pro

    => Booting WEBrick…
    /InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-1.2.1/lib/commands/servers/
    webrick.rb:11: warning: already initialized constant OPTIONS
    C:/Programme/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/comman
    ds/servers/mongrel.rb:18: undefined method `options’ for []:Array (NoMethodError)

  24. sur says:

    Hi Nannakey,
    I am not sure whether the problem is with instant rails or not, i havnt used it ever.
    Although the plugins works absolutely fine on XP from rails 1.6.6 – rails 1.2.3…
    You can try running you application by removing the plugin just by deleting the directory vendor/plugins/simple_captcha, lets see where the problem is… in the plugin or in the instant rails per se.

    Thanks

  25. sur says:

    For Mac and Linux Users

    If you are running SimpleCaptcha on Mac or Linux and getting some font related errors, you must check whether you have properly installed following libraries…

    • jpeg
    • png
    • freetype
    • ghostscript

    and after these, the most important ImageMagick, RMagcik will only work fine if these libraries have been installed properly.

    To test that these libraries are running fine on your machine, run this command from the console…
    convert label:1234 test.jpg … and try opening the file test.jpg in some picture viewer and if it opens properly there, simple_captcha will work absolutely fine.

  26. Michael says:

    Great little plugin! I was so pleased to find something like this and even further pleased at the ease of use. I got this up and running amazingly quickly. Didn’t have rmagick installed (or any of its dependencies) and that took only a few minutes to get going by using the binary download available for win-32 platform. I did have to change the font as referenced in preceding posts.

    I do have one question and am not sure if it is because I’m doing something incorrectly or if it is just a limitation of the plugin but…

    I have a form. If I fill it out, leave some of the fields blank that have validates_presence_of on them then the form will repost with the error message and fields that were already populated with the data still in them. However, if I fill some fields out, DO NOT put a value for the captcha and do the same thing then the form is redisplayed and all the fields are cleared. I really just want my user to try the captcha again w/o having to retype everything else. Any suggestions?

    Thanks,

    Michael

  27. sur says:

    Hi Michael,
    The auto-filling on form has nothing to do with the plugin simple_captcha per se.
    The reason for this is might be that in controller you are not using model’s instance variables with “@” viz. @user so that it will be available in the view, or if you are redirecting on the form page… so try to use model’s classes’ instance variables with “@” and do render :action instead of redirect. I hope it should work.

    Thanks

  28. Michael says:

    Sur,

    I think what you say is accurate, but here is the controller code behind the action and I think you can see that it is (should) be exactly the same regardless of cause for failure (i.e. – save failed because of model validation or save failed because of captcha_valid:

    def create
    if simple_captcha_valid?
    @lead = Lead.new(params[:lead])
    if @lead.save
    flash[:notice] = ‘Quote was successfully created.’
    redirect_to :action => ‘quote_confirmation’
    else
    render :action => ‘request_quote’
    end
    else
    flash[:error] = ‘Image Verification Failed. Please try to validate the letters in the image again.’
    render :action => ‘request_quote’
    end

    end

    As a point of reference, request_quote is the action invoked that subsequently causes the create to be called. Again, I see completely different results when the captcha fails versus when a required field fails (validates_presence_of in the model).

    Sorry to clutter your blog with something that may not be related, I’m just not certain why I have the different behaviors.

    Michael

  29. sur says:

    I got your problem Michael…

    move the line @lead = Lead.new(params[:lead]) one step above i.e. out side the if block, so that it will be available to the else section too.

    as…

    def create
    @lead = Lead.new(params[:lead])


    end

    I think it should work this way.

    Thanks

  30. Michael says:

    OMG…I feel like an idiot! Yes, of course, that solved the problem. Thank you so much. Also, your plugin is fantastic – I wish you the best of success and greatly appreciate you releasing this into the community.

    Michael

  31. sur says:

    Thanks Michael!

  32. Ben Taitelbaum says:

    First, thank you for such a wonderful plugin.

    We’ve run into some problems with the tmp and public/images directory permissions since we’re using capistrano for redeploys, and can’t always manually update the directory permissions. We’ve added some workarounds to our cap tasks, but would like to be able to remove them.

    I’ve created a ticket on rubyforge for this, but I’m wondering if anyone monitors this:
    http://rubyforge.org/tracker/?atid=11593&group_id=3009&func=browse

    Basically, I believe that changing 777 to 0777 in the calls to Dir.mkdir would fix the issue.

  33. sur says:

    Hi Ben,
    you know what…I am a lazy fellow… :D
    I did know this, as one of my friend was using capistrano and was getting same kinda prob…we fixed it there only but i didnt update the repository…

    Thanks for reminding me the same :)

    I have updated the repository now.

  34. renuka says:

    hello,
    if any user enter captcha code in lowercase then it doesnt give any error. i think it shouldnt be work it gives error so anyone can tell me what to do for that.

  35. renuka says:

    hi,
    can i check this captcha validation using javascript??
    because i want to check at client side not server side so pls help me as soon as possible.

  36. sur says:

    Hi Renuka,

    1.) The plugin has been deliberately written as a case-insensitive and will also ignore any spaces in the string too. If you want to change the behavior to case-sensitive, u will need to modify the code manually.

    2.) There aint any point validating the captcha on client side, if that would be the case….the bot script can easily be written to use your client side JS function to get the captcha validated.

    Thanks.

  37. renuka says:

    thanks for yr reply

  38. renuka says:

    hello sur,
    i want to display captcha in lowecase so can u say me for that where i have to change the code pls give me ans as soon as possible.

  39. sur says:

    The plugin is open source…You have the code!!
    Hack it…change it…use it!!

    At least burn some iron on your own baby!!

  40. renuka says:

    ok i have done that :)

  41. Vali says:

    Hi Sur,

    Great job you did here ! That’s realy cool !
    While playing with this, I was wondering whwo to change the background color if back or white is not exactly what you’re looking for.

    As a suggestion, if you plan to add this small feature, it will be great.

    Meanwhile, for those who can’t wait a new realease, like me, here’s how to modify it to support background color:

    1) in simple_captcha_image.rb file
    arround line 99 add the follwing line
    :bgcolor => options[:bgcolor] || “white”
    afrer line with
    :string => string,

    don’t fonget to add a comma after the above line.

    arround line 52, replace the “white” string with options[:bgcolor]
    image = Image.new(110, 30){self.background_color = options[:bgcolor]}

    2) in your rhtml, just add the :bgcolor to your options, something like this:

    “user”,
    :image_style => “simply_green”,
    :label => “human authentication”,
    :bgcolor => “#181818″
    ) %>

    Hope it will help.
    Cheers,

    Vali

  42. sur says:

    Hi Vali,

    Thanks for your code.

    I got the similar kind of response related to background color and images from Srinivasan.. I will definitely try to incorporate the code from u guys in the coming version/revision..

    Thanks

  43. palash basu says:

    hi
    i have done it….it was really a great thing, thanks

  44. Brian says:

    On Windows XP, ruby 1.8.5, rails 1.2.3: I installed RMagick just fine. Without the simple_captcha plugin everything works great, but when I add it I get the following error when starting my webrick server…please advise…thanks.

    c:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/servers/webrick.rb:11: warning: already initialized constant OPTIONS
    c:/ruby/lib/ruby/gems/1.8/gems/rmagick-1.14.1-win32/ext/RMagick.so: 126: The specified module could not be found. – c:/ruby/lib/ruby/gems/1.8/gems/rmagick-1.14.1-win32/ext/RMagick.so (LoadError)
    from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:33:in `require’
    from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in `require’
    from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:342:in `new_constants_in’
    from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in `require’
    from c:/ruby/lib/ruby/gems/1.8/gems/rmagick-1.14.1-win32/lib/RMagick.rb:11
    from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:33:in `gem_original_require’
    from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:33:in `require’
    from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in `require’
    … 32 levels…
    from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:33:in `require’
    from ./script/server:3
    from -e:4:in `load’
    from -e:4

  45. Brian says:

    Nevermind…just needed to restart RadRails to get all the new paths from the ImageMagick install.

  46. Jason says:

    You have a small type on this page, @user.save_with_cptcha should be @user.save_with_captcha

  47. sur says:

    Hi Jason,

    Thanks for observing the typo!

  48. Does it work on UNIX?

  49. sur says:

    Hi RubyonRailsExamples,
    It runs absolutely fine on WinXP, Linux and Mac… the condition is u should install the ImageMagick, jpeg, png, freetype and ghostscript libraries properly which are required by RMagick gem to work properly.

    Thanks.

  50. Jerry says:

    distortion is very useful,this is my opinion.
    What’s time we can get this function? Thanks.

  51. sur says:

    Hi Jerry,

    this function is available in the latest code… I think u r using previous svn url… please check out the fresh code from svn://rubyforge.org/var/svn/expressica/plugins/simple_captcha

    Thanks.

  52. Jerry says:

    hi,sur

    Can we separate label attribute from show_simple_captcha? sometimes,we want to set label position on page with freedom,but now the attribute be integrated then it will be shown under the images alway.

  53. sur says:

    Yeah, thats the older one!

  54. Jerry says:

    hi,sur

    Can you give me a complete example? I want to know how to valid.
    thank you!

  55. sasaki says:

    Hello!

    This is very simple, useful and COOL!!!!
    I love it very much. :-)

    And this plugin conflicts with the file_column plugin under my environment.
    I think it is because of Magick.

    I change the simple_captcha_image.rb script as follows:

    3c3
    #include Magick
    41c41
    text = ::Magick::Draw.new
    46c46
    self.gravity = ::Magick::NorthGravity
    52c52
    image = ::Magick::Image.new(110, 30){self.background_color = ‘white’}

    Thank you!

  56. sur says:

    Hey Jerry,
    The example is given in the post per se under the heading of Usage.

    Hi Sasaki,
    glad to know that u like(love) it :)
    I have modified the plugin as u suggested… replaced the inclusion of Magick module and used it as Magick::Image etc.

    Thanks.

  57. Yuriy says:

    Hi,

    I am getting an error while processing the following call from a view:

    show_simple_captcha :o bject => ‘comment’

    Error:

    undefined method `cur_image’ for 110×30 DirectClass 8-bit:Magick::Image

    #{RAILS_ROOT}/vendor/plugins/simple_captcha/lib/simple_captcha_image.rb:43:in `annotate’
    #{RAILS_ROOT}/vendor/plugins/simple_captcha/lib/simple_captcha_image.rb:43:in `add_text’
    #{RAILS_ROOT}/vendor/plugins/simple_captcha/lib/simple_captcha_image.rb:73:in `add_text_and_effects’
    #{RAILS_ROOT}/vendor/plugins/simple_captcha/lib/simple_captcha_image.rb:104:in `create_image’
    #{RAILS_ROOT}/vendor/plugins/simple_captcha/lib/simple_captcha_action_view.rb:72:in `show_simple_captcha’

    Ahy help is appreciated.

  58. Great Work! Thank you for solving a problem I was facing with such a great solution.

    It all seems to work well. One question… Are there any tests that have been written for the plugin yet? I installed the latest release of the plugin and noticed that there were no tests written. Am I missing them? Has anyone out there written any?

    Thanks again!

  59. sur says:

    Hi David,

    I have done the testing in the test application stub in which i developed the plugin… i didnt find it useful to serve them with the plugin.

  60. Alan Kirk says:

    Hi there,

    Thanks for the great plugin, exactly what i’ve been after.

    Now, i’ve got a special talent when it comes to really simple implementations of code and them not working properly. I’ve got the plugins all installed and got the view for my registration page showing the validation image. My problem seems to lie when trying to validate the code typed into the box as everytime i submit the form with any version of the code (upper and lowercase) it never seems to validate. I’ve used the validation code in the example above, but can submit the actual code i’ve used if it helps. When i click submit it throws out the error message i put in for when then codes do not match up.

    Is there something i can do to output out the code being submitted and being compared with so i can test that the form is being submitted proplerly?

    Many thanks in advance

  61. sur says:

    Hi Alan,

    I hope you must have restarted the server after installing the plugin! Can you show/mail me the code where you are validating the captcha ?

  62. Alan Kirk says:

    Hi Sur,

    Thanks for the reply. Here’s the code that i’ve got.

    My model user.rb has:

    class User < ActiveRecord::Base
    validates_presence_of :password, :o n => :update
    validates_confirmation_of :password, :o n => :update, :message =>
    “Passwords don’t match.”
    apply_simple_captcha
    end

    User Controller

    def addprofile
    @pageTitle = ‘ – Add User Profile’
    @user = User.find(@params[:id])
    @userEmail = @user.email

    if request.post?
    if simple_captcha_valid?
    @user.update_attributes(@params[:user])
    redirect_to :action => ‘thankyou’
    else
    flash[:notice] = ‘You have not typed in the correct verification
    image code. Please read carefully and try again.’
    end
    end
    end

  63. Disha says:

    thanks for the wonderful plugin

  64. sur says:

    Thanks Disha

    ===============================

    Hi Alan,

    The problem you are facing is because you are intermixing the two kind of SimpleCaptcha implementation viz. model_based and controller_based.

    Please again go through the example of each type i mentioned above in the post.

    Code in the following manner
    For Model Based Implementation
    in model – apply_simple_captha
    in view – show_simple_captha with :o bject option
    in controller – @user.save_with_captcha

    For Controller Based
    in model – nothing
    in view – show_simple_captcha without :o bject option
    in controller – simple_captcha_valid?

    In your use case i will suggest you to go for controller based, because you are updating the record not saving a fresh record.

    Thanks

  65. Alan Kirk says:

    Sur,

    You are a star!

    Thanks again for your help.

  66. Thanks for this plugin. It’s working great for me locally. And works in deployment too, but with an odd twist. The text in the captcha isn’t centered in the image. Instead it displays at the very bottom of the captcha image (clipping off a few pixels along the text’s bottom I think) leaving most of the captcha image blank.

    Has anyone else run into this problem, or have ideas for a solution?

    Thanks,
    Jesse

  67. sur says:

    Hey Jesse,

    Seems like the problem is in RMagick or one of its dependencies… Make it sure that all the libraries have been installed properly on your system.

    Thanks.

  68. addame says:

    Hi there !

    Thanks for the great plugin and tutorial.

    It’s said that it’s working with rmagick and I wonder if it can work using image_science.

    Cheers,

    Addam

  69. sur says:

    Hey Addam,

    I think ImageScience is not as versatile as RMagick… Though i haven’t used it yet, so i dont know if it can provide the similar functions which i am using from RMagick. If you wanna use ImageScience, you will have to recode all the plugin by replacing the RMagick’s functions with ImageScience.

    Thanks

  70. [...] E X P R E S S I C A » Simple Captcha 1.0 (tags: rails captcha plugin rubyonrails security) [...]

  71. [...] minutes before a demo the other day, so I scrambled a researched for five minutes and settled on Simple Captcha. It had the features I needed, and looked like it could be implemented fast. So how did I [...]

  72. sur says:

    Hi Matthew R. Miller,

    I am glad to know that you found it useful.

  73. [...] E X P R E S S I C A » Simple Captcha 1.0 – [...]

  74. Vincent Liu says:

    68.Jesse Grosjean said …

    Thanks for this plugin. It’s working great for me locally. And works in deployment too, but with an odd twist. The text in the captcha isn’t centered in the image. Instead it displays at the very bottom of the captcha image (clipping off a few pixels along the text’s bottom I think) leaving most of the captcha image blank.

    Has anyone else run into this problem, or have ideas for a solution?

    Thanks,
    Jesse

    —————–

    I’ve found a workaround to that, by changing line 45 of ‘simple_captcha_image.rb’ from:


    text.annotate(options[:image], 0, 0, 0, 5, options[:string]) do

    to


    text.annotate(options[:image], 0, 0, 0, 5, options[:string]) do

    Hope it helps!

  75. Vincent Liu says:

    I meant:


    text.annotate(options[:image], 0, 0, 0, 0, options[:string]) do

    Sorry for the confusion.

  76. Guillaume says:

    Hi,

    I just found your plugin, and i m trying to implement it on my form, where user can register… i succefully installed it, but i ve some trouve with the validation of the captcha.. i noticed there were two method, controller and Model.. i fugured out to use the model one…

    Here is my controller code :

    def create_account
    @v = flash[:v]
    if @v.nil?
    @v = Membre.new
    end
    end

    def valider_account
    id = params[:id]

    if id.nil?
    @v = Membre.create params[:v]
    else
    @v = Membre.update params[:id], params[:v]
    end

    if @v.errors.count != 0
    flash[:v] = @v
    redirect_to :action=>”create_account”
    else
    redirect_to :action=>”lister”
    end

    end

    My view include :
    “v”)%>

    and my model include :
    apply_simple_captcha :message => “image and text were different”

    Well i ll would like to be able to check the validity of the code that a user type, and if it s wrong, i would like to show an errors in the forms…

    Thank you for helping me, i m kind of lost

    Guillaume.

  77. sur says:

    Hi Guillaume,

    please figure out what the code flash[:v] = @v is doing…

    i think flash[:v] = “some string message”

    Thanks.

  78. Artur says:

    Hi, Sur.
    I like your plugin and I use it in my current project. But there is a conflict with WebORB plugin (http://www.themidnightcoders.com/weborb/rubyonrails/index.htm). SimpleCaptcha and WebORB for Ruby can’t work togrther.

    error from development.log:
    TypeError (UndefinedType is not a class):
    /vendor/plugins/weborb/lib/weborb/reader/undefined.rb:26
    c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require’
    c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require’
    c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in `require’
    c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:342:in `new_constants_in’
    c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in `require’
    /vendor/plugins/weborb/lib/weborb/formats/amf_request_parser.rb:38
    c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require’
    c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require’
    c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in `require’
    c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:342:in `new_constants_in’
    c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in `require’
    /vendor/plugins/weborb/lib/weborb/formats/parser_factory.rb:22
    c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require’
    c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require’
    c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in `require’
    c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:342:in `new_constants_in’
    c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in `require’
    /app/controllers/weborb_controller.rb:23

    this error appeared on first veborb request. Both plugins works fine without each other.

  79. sur says:

    Hi Artur
    I cant see any error of simple_captcha in the above exceptions :)

    Anyways, please figure it out why it is not working with webORB, find the way how they both can be in sync…

    let me know if there is any generic change in the simple_captcha plugin can solve the issue, I will modify the plugin accordingly.

    Thanks.

  80. Guillaume says:

    Sorry but it s not my question…
    How do i validate the code using the code i described above ?

    thanks

  81. rishav says:

    Was able to use your captcha in less than 2 minutes, thx for such a nice plugin.

    ~rd
    http://sazwqa.wordpress.com

  82. sur says:

    Hi Guillaume,

    Controller’s and model’s seems fine to implement captcha.
    But, i didnt get whats in your view, please mail me the view content.

  83. sur says:

    Hi Guillaume,

    The reason why you are not able to validate the captcha is that you are not using the right function to validate the object while creation.

    You should use it this way

    @v = Membre.new(params[:v])
    @v.save_with_captcha

    thanks.

  84. Guillaume says:

    Hum i ll try and let you know, thanks a lot

  85. Guillaume says:

    It works !!! it s kind of magic… if people are interested, there how it works :

    if id.nil?
    @m = Membre.new(params[:m])
    @m.save_with_captcha
    else
    @m = Membre.update params[:id], params[:m]
    @m.save_with_captcha
    end

  86. Michael M says:

    Hey,

    Thanks for the fantastic plugin. I was able to get it to work sucessfully with the controller implementation, but that separated my validations. I’m assuming this is an advantage of the model based approach: all validations are contained in the model. I’m having trouble getting this to work however. No validations seem to trigger, even if other elements of the form are invalid (they were working fine before), though the record is not saved. I added the apply_simple_captcha line as the first line in my model. My controller looks like this:

    @user = User.new(params[:user])
    return unless request.post?

    @user.save_with_captcha #…for saving user object with captcha validation
    self.current_user = @user
    redirect_back_or_default(:controller => ‘/account’, :action => ‘index’)
    flash[:notice] = “Thanks for signing up!”

    rescue ActiveRecord::RecordInvalid
    render :action => ‘signup’
    end

    Any help would be appreciated. Still relatively new at this… Thanks.

  87. Michael M says:

    So, after further investigation, I think that the problem is my validation depends on using the “save!” command, not just “save”. Using “save_with_captcha!” returns an undefined method error. I guess I’m not really sure how the “save_with_” command works exactly and how I would replicate the functionality of the exclamation mark. Any suggestions? Thanks again.

  88. James George says:

    Can anyone help me with this error. I have installed the ImageMagick and also done the gem instal rmagick. Also installed the latest libjpeg files. Reading at some other place, showed that I needed to install jasPer2 lib and inspite of installing the same results in the same error.
    So please anyone out there can help me find a solution is greatly appreciated,
    Thanks in advance.

    Showing app/views/users/new.rhtml where line #5 raised:

    no encode delegate for this image format `script/../config/../public/images/simple_captcha/c0f30b3679254826e1ce5f4449728fb6d917feca.jpg’

    Extracted source (around line #5):

    2:
    3: ‘create’ do %>
    4: ‘form’ %>
    5: “user”) %>
    6:
    7:
    8:

  89. sur says:

    Hi Michael, Hi James !!

    @Michael
    there isn’t any function as save_with_captcha!, in order to utilize this captcha plugin you will have to use save_with_captcha function only.

    @James
    There is problem in your RMagick, are you sure you have installed ImageMagick, Rmagick and all dependent libraries properly on your system ?

  90. Greg says:

    Hi,

    I’m getting an “undefined method `options’ for []:Array (NoMethodError)” at start-up (full error details below). I’m running Ruby v1.8.6, Rails v1.2.3 on Mac OS X.

    If I comment out lines in the plugin’s “init.rb” entry one by one, restarting the server each time, I found the problem occurs when the 2nd line of this file is hit, that is:

    require ‘simple_captcha_image’

    The full error is:

    greg$ ruby script/server => Booting Mongrel (use ‘script/server webrick’ to force WEBrick)
    => Rails application starting on http://0.0.0.0:3000
    => Call with -d to detach
    => Ctrl-C to shutdown server
    ** Starting Mongrel listening at 0.0.0.0:3000
    ** Starting Rails with development environment…
    Exiting
    /Applications/Locomotive2/Bundles/standardRailsMar2007.locobundle/i386/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/servers/mongrel.rb:15: warning: already initialized constant OPTIONS

    Any advice from anyone here?

    Regards
    Greg

  91. sur says:

    Hi Greg,
    The error undefined method options (or OPTIONS) occurs if you are trying executing some code which is requiring some module or library which is not installed on your system.

    The most probable reason that you are getting the error in second line is that you are missing the RMagick library(or one of the dependent library which is used by RMagick). Make it sure that you have installed ImageMagick, RMagick and dependent libraries properly on your system and RMagick is working.

  92. Greg says:

    Hi sur – I’ve installed these and they seem to work based on some simple tests. I’m guessing perhaps it the manner in which rails looks for / loads these modules this might be occurring then(?). It does seem to be at the “require ‘RMagick’” stage within “simple_captcha_image.rb” that it is sensitive to this.

    arr…just jumped into “irb” and a “require RMagick” isn’t working, even though I know it’s installed. I’ll have to read up on how the rails environment references gems. Actually when installing RMagick (http://rmagick.rubyforge.org/install-osx.html) at Step 6 I did take option B approach “install from source tar ball” (not the option A via GEM approach). I wonder if this has meant it hasn’t been registered as a GEM properly….more digging required..

    Regrds
    Greg

  93. sur says:

    Well, if u are doubtful about RMagick installation then you can try on irb like this…
    first require rubygems and then rmagick

    require ‘rubygems’
    require ‘RMagick’

    if both returns true then add the first line in the plugin also, it might work for you… well, it worked for me in some cases when rubygems needed to be required explicitly.

  94. Ryan says:

    Hi Sur,

    excellent work on the plugin and your article here.

    Is there a way to generate the captcha image name, and text field with two different calls from within my view code, instead of generating all of the html with the show_simple_captcha method? This is so I can format the html of the input field, label, and image differently from the format that is generated by the show_simple_captcha method call.

    Thanks for developing simple_captcha!

    Ryan

  95. Greg says:

    update – got things working :) Turned out to be due to my RMagick installation was actually going into a different Ruby installation on my machine, not the one I wanted to go into.

  96. sur says:

    Hi Ryan,

    Though there aint any direct method to fetch the individual element, but you can use Hpricot tricks to parse the HTML quite easily. Use it like this…

    First install the hpricot gem simply by “gem install hpricot” then in your views use it as …

    < % require 'hpricot' %>
    < % doc = Hpricot.parse(show_simple_captcha) %>
    < % image, text, field = (doc/ :div/ :img).first.to_html, (doc/ :div/ :p).first.to_html, (doc/ :div/ :p).last.inner_html %>

    Now, you can put these ruby variables containing individual elements with custom formatting.

    Thanks.

  97. Stephen says:

    I think there’s a problem with non-unique session.session_id values used to generate the hash in the create_code function. The session.session_id evaluates the same for different user sessions. When they both try to use simple_captcha at the same time, the user trying to use an “old” captcha string does not get validated. The user who uses the “latest” captcha image/value gets validated.

    Am I missing something here? Do I need to configure my session somehow?

    Thanks for the otherwise great plugin!
    (I can get by for a while with this issue, since I’m not expecting a lot of simultaneous posting yet.)

  98. sur says:

    Hi Stephen,
    I didnt get what exactly u meant by non-unique session_id values, if session_id can be non-unique then there isn’t any concept of session per se. Two sessions can never hold same session_id… The problem you are facing might be that you are trying two different users from same browsers tabs.. are you ?
    Note that in the same browser, for the same url there cant be two different sessions.

    Thanks.

  99. Stephen says:

    Yes, that was it! I only had problems when using two different users on different tabs of the same browser. That’s not a common nor important case. Things work fine when different users are on different browser windows. Thanks.

  100. niladri says:

    Hello Sur,

    I am facing the same problem as detailed by Yuriy on 05/17/2007 (at 12:24 pm) – i.e, on invocation of show_simple_captcha from a view, I face the following error

    undefined method `cur_image’ for 110×30 DirectClass 8-bit:Magick::Image

    I am on Win XP and using Ruby 1.8.6 and RMagick-Win32 installation that is available at RubyForge. On commenting the following lines in your simple_captcha_image.rb

    text.annotate(options[:image], 0, 0, 0, 0, options[:string]) do
    self.font_family = ‘arial’
    self.pointsize = 22
    self.fill = options[:color]
    self.gravity = Magick::NorthGravity
    end

    the page comes up – but of course, we dont get the captcha functionality anymore. Any ideas on how to get around this problem would be very much appreciated.

    Thanks

  101. 2fas2c says:

    Excellent plugin. Everything works fine on my development machine (Windows XP, Webrick, Ruby 1.8.5, Rails 1.2.2) but when I run the same code on my production server (Linux, FastCGI, Ruby 1.8.5, Rails 1.2.2), the image shows up with no text on it. I don’t see any errors in the log file. Please help.

    Thanks

  102. sur says:

    Check whether RMagick is working fine on your server.

  103. 2fas2c says:

    It looks like RMagick is installed on my server. I would have expected it to throw errors if some of the dependencies are missing.. Also the image is getting generated under images/simple_captcha directory, but it’s a blank image with just border and no string.

    *********************************
    bash-3.00$ irb
    irb(main):001:0> require ‘rubygems’
    => true
    irb(main):002:0> require ‘RMagick’
    => true
    irb(main):003:0> exit
    bash-3.00$
    *********************************

    Thanks

  104. boothdeveloper says:

    since there is only one valid captcha per session at a time, does anyone think about supporting more than one? any sounded implementations done?

  105. Osama Brekaa says:

    hi,

    in the beginning i want to thank you for your plugin, it’s very nice

    and i want to suggest something to modify it in the next revision of the plugin
    in simple_captcha_valid?, this method depends that the params hash has :captcha and also :captcha_code but if there is a form_for :user for example, he won’t have params[:captcha] and params[:captcha_code] but params[:user][:captcha], so why don’t you make this method more generic like that

    simple_captcha_valid?(captcha_hash = params)

    This way i can solve the problem i said by saying simple_captcha_valid?(params[:user])

    and also this gives us backward compatability

  106. Osama Brekaa says:

    Also can’t we work on this plugin more to try to add Audio capability for handicapped users

    This will be nice from you and maybe we can work together in that although i am not expert in Ruby

  107. kiwi says:

    here is some tips for people encounter a problem when setup on Windows XP (which I had spend 2 , 3 days to make it work, it you also encounter problem, below, it might help you)

    install RMagick-1.14.1_IM-6.3.0-7-Q8 from http://rubyforge.org/projects/rmagick (select the win-32 version), unzip and run the installer.

    go to the unzip dir with command prompt and enter this :
    >gem install rmagick
    this install the rmagick win-32 version.

    *DON’T install like this !!
    >install gem rmagick
    (this will install linux version, which may not working)

    you should see the successful install message.

    next check the version of rubygems
    > gem -v

    if the version is 0.9.4, RMagick will NOT working !! (0.9.2 is OK !)if you encounter something like cur_image not found..mostly is due to the rubygems version.

    install the 0.9.2 version to make it work !
    http://rubyforge.org/frs/download.php/17189/rubygems-0.9.2.zip
    unzip to C:\ruby\lib\ruby\gems\1.8\gems and open the unzip folder. run install.rb

    after finish the version of rubygems should be 0.9.2
    >gem -v
    0.9.2

    here is some tip:

    1) => Booting WEBrick…
    /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.1/lib/commands/servers/
    webrick.rb:11: warning: already initialized constant OPTIONS
    —- if not install RMagick, you will see this error.

    2) sample in C:\ruby\lib\ruby\gems\1.8\gems\rmagick-1.14.1-win32\examples not working.
    to run the sample, open the file and add this line above other require

    require ‘rubygems’
    require ‘RMagick’

    (this is already load in rails but not other app)

    that is it !

    hope this help !

    happy hacking :)

  108. Markus says:

    Great plugin, Sur! Unfortunately I have a minor problem with it: The validation of the captcha always fails (“Captcha image did not match with text”). I can’t figure out why. I tried controller based as well as model based (which I prefer). Perhaps someone can help me out. Here is my code for the model based version:

    # comment.rb

    class Comment New comment

    ‘create’ do %>
    ‘form’ %>

    “comment”) %>

    ‘list’ %>

    # comments_controller.rb

    # (all scaffolded stuff, only changed @comment.save_with_captcha)

    def create
    @comment = Comment.new(params[:comment])
    if @comment.save_with_captcha
    flash[:notice] = ‘Comment was successfully created.’
    redirect_to :action => ‘list’
    else
    render :action => ‘new’
    end
    end

  109. Markus says:

    Woops, some of the code above isn’t shown right. So, basically its all scaffold, I only changed.

    #new.rhtml
    show_simple_captcha(:object=>”comment”)

    # comment.rb
    class Comment

  110. Markus says:

    OK, I’m a complete idiot. Figured out what the problem was. I placed the show_simple_captcha(:object=>”comment”) outside my submit form, so the captcha answer was never submitted. Sorry bothering you! Great job, again!

  111. Lenni says:

    Hi there, thanks for this nice plugin.
    As I use something like @user.save!, I wrote:
    if @user.save! && simple_captcha_valid?
    self.current_user = @user ….
    else
    @user.destroy …
    end
    As @user.save! might add an User to my database,I used @user.destroy to remove him if the captcha validatoin isnt true.
    As this all works fine for me, I have some Problems to arrange the captcha text-field beneath the imagefield.
    This is the normal format (text under image):
    captcha-Image
    captcha-textfield
    and I want image and text in one line:
    captcha-image textfield
    I played around with the simple_captcha_action_view.rb, but …hmmm.. Hope someone has an idea
    regards, lenni

  112. sur says:

    Hey Lenni,

    First of all I would like to say that your code holds a major flaw as it is inserting unnecessary records in db and then removing them… it should simply be

    if simple_captcha_valid?
    @user.save!
    self.current_user = @user
    else
    flash[:warning] = “some warning message”
    end

    Anyways, for the custom alignment of the captcha fields you can see this comment.

    regards,
    sur

  113. Lenni says:

    Thanks for the link, sur.
    Ure right, its not very nice to insert and then destroy records.
    I did an @user.save before a simple_captcha_valid because if I do the captcha-validation first and it returns false and if i then render the “create_account” page again, the other user_fields doesnt get any validations. I think, the user fields are then empty,too, and the user has to fill in everything again. In my version I validate all fields (the normal fields AND the captcha) , so the user has to fill in just the missing/incorrect fields (if captcha field is ok, he doesnt have to fill it up again also)
    This is my complete code for method create:
    def create
    @user = User.new(params[:user])
    if @user.save! && simple_captcha_valid?
    self.current_user = @user
    UserMailer.deliver_registration_confirmation(@user)
    render :action => ‘account_successfully_created’
    else
    @user.destroy
    flash[:notice] = “captcha_not_ok”
    render :action => ‘account_creator’
    end
    rescue ActiveRecord::RecordInvalid
    render :action => ‘account_creator’
    end

    Ure welcome to tell me how to do it better,
    thanks in advance and best regards, sur

  114. Lenni says:

    whats up, big sur ? :)
    is there anything u c/should u tell me ?
    I think i save the user-data with user.save! (nice english :) )
    if someone takeshis time to fill out all fields in my form, doesnt he deserve to live in my database just for 1/10 secend ?
    Please send another solution.
    thx

  115. sms says:

    Not good at all ..

    This one needs RMagick .. it’s mentioned in this article ..
    But RMagick needs ImageMagick and GraphicsMagick.

    I have ImageMagick .. but it really needs the development version
    I don’t have GraphicsMagick and they don’t give out any “rpm/deb/tz” packages .. so you have to compile BOTH of these packages from source and have to understand all the options to build and frankly I don’t know if it will work as advertised “after all this”.

    1 line .. 5 minutes —- hardly .. more like half a day if you are good and probably a few days to make sure everything is right.

    Want to help .. at least tell this upfront .. I spent more than an hour chasing all this already.

  116. sur says:

    It has not been advertised to fetch the dollars out of your fatty wallet. The plugin has simply been released in the open source community and a lot of applications are easily using it including all of mine. For information on how to install RMagick + Imagemagick and dependencies, if you are on ubuntu you can go through this post

  117. Thomas says:

    We needed a captcha and we googled for a simple solution. And we found you. You solved our problems great. It could not have been easier.

  118. hiutopor says:

    Hello

    Very interesting information! Thanks!

    G’night

  119. Ariel H. Pillet says:

    Amazing plugin :)

    Thanks!

  120. Dianna says:

    Great plugin – thank you!!

    Is there any way to customize the error message? I’m assuming people using my form are going to see “Captcha image did not match with text” and be like “What is a captcha????”
    :) Thanks again!!

  121. sur says:

    Hey Dianna,

    you can give the custom message in model centric implementation as

    apply_simple_captcha :message => “custom error message”

    Thanks.

  122. Dianna says:

    Thanks!

    To those people who don’t want it called “captcha” in the error message, here is what I did…

    In my model,

    apply_simple_captcha :message => “custom error message”

    Open “/vendor/plugins/simple_captcha/lib/simple_captcha_active_record.rb”

    Change line 58 from:

    self.errors.add(:captcha, “#{@captcha_invalid_message}”)

    to:

    self.errors.add_to_base(“#{@captcha_invalid_message}”)

    Now, instead of saying “Captcha (message)” it will only display your message “The code you entered did not match”, or whatever.

    Thanks, Sur!

  123. sur says:

    Thanks Dianna,

    that will help others as well in getting the nerdy “Captcha” word removed form the end user’s UI.

    I will put it more generic way in the code as well.

    Thanks.

  124. Alex says:

    Hi Sur,
    How is it possible to configure what characters to be allowed in the captcha image? What I mean is I would like the captcha image to include upper-case and lower-case characters as well as numbers. More than that it would be nice to have characters appear in captcha image case sensitive, but validation to be not case sensitive.

  125. Alex says:

    Never mind, I needed just a couple changes in simple_captcha_image.rb.

  126. kai says:

    I added the implementation for save! and save_with_captcha!
    see http://snippetsnap.com/snippets/4184-New-Snippet for code snippet

  127. sur says:

    hey Kal,

    snippet looks good, after testing will add the code in repository with next version and your name in contributors list.

    thanks.

  128. kai says:

    Sur,
    can you provide the option to use mini_magick instead of RMagick ?
    mini_magick is supposed to use a lot less memory than RMagick.

    According to
    http://www.thoughtstoblog.com/articles/2007/5/19/railsconf-2007-xen-and-the-art-of-rails-deployment
    http://mephistoblog.com/2007/1/9/new-asset-thumbnailing-options-available ,

    getting rid of RMagick is key to vicotry!

  129. Thomas Beck says:

    For those of you with complaints about the functioning of this plugin in Windows environments, especially with errors relating to ‘cur_image’ ( I count 3 posts related to this), check to make sure that you have the rmagick-win32 gem v1.14.1 or higher installed. This gem fixed problems related to RubyGems 0.9.4 (hence the hack suggestion above to downgrade to RubyGems 0.9.2). I had similar problems to those noted above and the upgrade to v1.14.1 solved my problems immediately.

    sur – thanks for the elegantly simple gem. Hopefully this will help some of us stuck on Windows dev environments.

    Thomas Beck
    http://www.beckshome.com

  130. kai says:

    I added the support of a secret captcha which can be used to bypass captcha validation during automated testing(such as using selenium)

    see http://snippetsnap.com/snippets/4219

  131. kai says:

    Note that the secret captcha support I outlined above only works for active record based captcha validation.
    But you can easily add the secret captcha support to controllers by modifying simple_captcha_valid? in simple_captcha_action_controller.rb
    changed
    return true if RAILS_ENV == ‘test’
    to
    return true RAILS_ENV == ‘test’ || (!ENV['secret_captcha'].nil? && ENV['secret_captcha'] == params[:captcha])

  132. [...] the hassle of getting DarwinPorts working, I ended up sacking-off the Turing gem and going for the SimpleCaptcha plugin for Rails. It’s not as pretty in its base form, but it bloody well works straight out [...]

  133. [...] популярной статье Ruby on Rails Security Guide пишеться о том, что simple_captcha не самый лучший вариант для защиты от спама именно о [...]

  134. Tobias says:

    Hi Sur,

    I just tested Simple Captcha and the images are displayed, but they are cut.
    convert label:1234 test.jpg works fine, but the images produced by Simple Captach in public/images/simple_captcha are moved in the upper half of the image.
    I use GraphicsMagick and Debian Linux. Any suggestions?
    Thanks in advance and best regards

  135. Tobias says:

    Works now, I use ImageMagick now

  136. Cass says:

    Hi,

    This is a wonderful plugin, it works great on my deveopment environment but when I am in the production mode on my staging site, the captcha image is not being displayed properly, its showing only half the image which makes it unclear to read. Could u please let me know what the problem could be?

    Cheers

  137. Kevin says:

    Tip: Make sure you have the Ghost Script (Type 1) fonts installed. On Ubuntu sudo apt-get install gsfonts. Otherwise ImageMagick chokes.

    Awesome plugin–thanks!

  138. kai says:

    Sur, I looked at the plugin source code, and it seems that the plugin reads off image from disk to compare the code inputted by user.
    Is there a reason why you don’t store the code in session?

    I am running multiple mongrels behind apache, and use memcache as the session store. Mongrels can run on different servers. so unless I use sticky session, one mongrel may generate the captcha image, another mongrel may get the request to verify the user-inputted code, but can’t find the captcha image on disk.

  139. xaktoman says:

    After suffering through many, many days of validates_captcha pain, I took the plunge and installed simple_captcha. HOLY JESUS/ALLAH/BUDDHA!! It just works!

    With validates_captcha, upgrading Rails/RMagick meant a broken image verification. Upgraded val_cap, no dice. Played for *days* trying to figure out what was wrong, exhausted every page on Google, etc. – still no dice. Then simple_captcha saved the day.

    Thanks for this plugin — it’s the best I’ve ever installed!

  140. Roy says:

    This looks like a cool idea, but I can’t get it to work for me.

    I have RMagic1.5.9-win32 and the corresponding ImageMagic installed. When I try to boot my server, I get the error messages shown below. If I comment out the require ‘RMagick’ in simple_captcha_image, Rails boots fine, but, of course, any attempt to use the captcha fails (uninitialized constant SimpleCaptcha::ImageHandlers::Magick)

    Running WebBrick service …
    RAILS_ROOT: C:/www
    => Booting WEBrick…
    C:\www\vendor\rails\railties\lib\commands\servers\webrick.rb:11: warning: already initialized constant OPTIONS
    c:/ruby/lib/ruby/gems/1.8/gems/rmagick-1.15.9-win32/ext/RMagick.so: 127: The specified procedure could not be found. – c:/ruby/lib/ruby/gems/1.8/gems/rmagick-1.15.9-win32/ext/RMagick.so (LoadError)
    from c:\ruby\lib\ruby\site_ruby\1.8\rubygems\custom_require.rb:32:in `require’
    from C:\www\vendor\rails\activesupport\lib\active_support\dependencies.rb:495:in `require’
    from C:\www\vendor\rails\activesupport\lib\active_support\dependencies.rb:342:in `new_constants_in’
    from C:\www\vendor\rails\activesupport\lib\active_support\dependencies.rb:495:in `require’
    from c:\ruby\lib\ruby\gems\1.8\gems\rmagick-1.15.9-win32\lib\RMagick.rb:11
    from c:\ruby\lib\ruby\site_ruby\1.8\rubygems\custom_require.rb:32:in `gem_original_require’
    from c:\ruby\lib\ruby\site_ruby\1.8\rubygems\custom_require.rb:32:in `require’
    from C:\www\vendor\rails\activesupport\lib\active_support\dependencies.rb:495:in `require’
    … 29 levels…
    from C:\www\vendor\rails\activesupport\lib\active_support\dependencies.rb:495:in `require’
    from C:\www\vendor\rails\railties\lib\commands\server.rb:39

  141. sur says:

    Roy,

    Make sure that RMagick is working on your machine. Try this in irb

    require ‘RMagick’

    to test if it is working or not!

    Thomas has suggested something for windows users on his post and in the comment (Thanks Thomas!!).. it might help you.

  142. Markus P. says:

    Hi Sur,

    on linux the text was not positioned correct. I only saw the bottom part of the letters.
    No problems on windows.

    After the following changes in simple_captcha_image.rb it works on both:

    text.annotate(options[:image], 0, 0, 0, 0, options[:string]) do
    ..
    self.gravity = Magick::CenterGravity

  143. Bala says:

    Hi,

    in Controller
    @user = User.find(params[:id])
    return unless request.post?
    @user.attributes=(params[:user])
    if @user.save_with_captcha
    #redirect_back_or_default(:controller => ‘/account’, :action => ‘index’)
    redirect_to(:controller => ‘/account’, :action => ‘index’)
    flash[:notice] = “Thanks for signing up!”
    end

    in model
    apply_simple_captcha

    in view
    ‘user’)%>

    this code works perfectly. but i hope this is not the way for applying simple captcha validation for update_attributes. so plz help me with this.

    regards,
    Bala

  144. nyajila says:

    Hi, Thank you for your plugin.

    I am using my monkey patch for your show_simple_captcha function.Because I would like to display the following input_tag.

    The monkey patch is following.
    ————–start————–
    def show_simple_captcha(options={}, initValue=”", onfocus=”void(0)”, onblur=”void(0)”)
    name = create_image(options)
    if options[:object]
    captcha_code = create_code
    field = text_field(options[:object], :captcha, {:value => initValue, :o nfocus => onfocus, :o nblur => onblur})
    field captcha_code})
    else
    field = text_field_tag(:captcha, initValue, {:onfocus => onfocus, :o nblur => onblur})
    end
    label = (!options[:label] or options[:label].empty?) ? “type the text from the image” : options[:label]
    ret =
    #{image_tag ‘simple_captcha/’ + name, :style => ‘border:1px solid #999′}

    #{field}

    EOS
    GC.start
    return ret
    end
    ————–end————–

    I think if “show_simple_captcha_image” function is return image_tag and “show_simple_captcha_field” function return text_field, We can design more freely.

    Sincerely yours. I am sorry for poor English.

  145. nyajila says:

    P.S.

    Sorry. input_tag is following.

    input id=”captcha” name=”captcha” onblur=”$(this).style.backgroundColor="white";if(""==$F(this)){$(this).value="Enter captcha text";$(this).style.color="gray";}” onfocus=”$(this).style.backgroundColor="#fff1ff";if("Enter captcha text"==$F(this)){$(this).value="";$(this).style.color="black";}” type=”text” value=”Enter captcha text”

  146. Bruce says:

    Bala,

    thanks for the note. I had the same problem. Worked fine on Suse 10, but the text dropped down on the RH box being used for production. Your trick sorted it. By the way, this is a really useful plugin. Thanks a lot for it.

    Bruce

  147. [...] a captcha in a form, whose associated model is a Validatable. After googling, I decided to go with Simple Captcha. The Simple captcha is extremely easy to use, see its documentation, you’ll know. But it [...]

  148. [...] a captcha in a form, whose associated model is a Validatable. After googling, I decided to go with Simple Captcha. The Simple captcha is extremely easy to use, see its documentation, you’ll know. But it [...]

  149. Jerry Liu says:

    How will this scale if we have two servers using it?

  150. Mike says:

    The captcha works perfectly for me. I am worried from memory leaks, but i need to inspect its code more.

  151. geoff says:

    I don’t think you need to use pstore to store the strings. Just store the string for the user on the session. The check in simple_captcha_action_controller.rb method simple_captcha_valid? becomes:

    @ret = session[:captcha] == params[:captcha].delete(” “).upcase

    and set in simple_captcha_image.rb method image_details is:

    session[:captcha] = string

    And you can delete the PStore data directory creation in simple_captcha_config.rb. This removes any issue related to the request going to one server while the response goes to another. (Since the db is usually shared between servers.)

  152. Dianna says:

    I’d like to have the captcha field highlight when it’s incorrect – the same as a field does (by default) on a form. How would I do this?

  153. Kurt says:

    Hi,

    I am having the same problem as Jesse above. The bottoms of my CAPTCHAs are clipped off. I don’t know what could be causing this. I had my host reinstall the latest version of RMagick and ImageMagick, but it didn’t fix anything. Do you know what might be causing this?

    -Kurt

  154. hg says:

    Hi.
    After installing the plugin, my server can not start anymore.
    i don’t even get an approiate error message. it just stops without any feedback.
    If i remove “vendor/plugins/simple_captcha” everything works fine.
    Is it maybe a version problem or has somebody another idea?
    Rails 1.1.6
    ruby 1.8.4

    Thx

  155. Igor says:

    Why can’t download???

  156. sur says:

    Update: SimpleCaptcha 1.2.0 is up!!

    Major Changes…

    No Pre-Requisites

    RMagick Removed

    FileSystem Usage Removed

    Works Perfectly with Multiple Clustered Servers

    Read Here for more details.

  157. [...] After looking around, I found this post that described how you could implement a plugin called Simple Captcha in 10 minutes or [...]

Sponsors