Rake task to remove the image and audio files created by captcha

October 16, 2006 at 12:33 pm Leave a comment

To add a rake task to the rails application which removes all the image and audio files created by captcha, create a file named remove_captcha_files.rake in the lib/tasks directory.
Add the following code to the lib/tasks/remove_captcha_files.rake file…

desc "Remove captcha images and audio files"
task :remove_captcha_files do
  image_path = "#{RAILS_ROOT}/public/images/captcha/"
  audio_path = "#{RAILS_ROOT}/public/captcha_audio/"
  Dir.foreach(image_path){|file| File.delete(image_path+file) if (/^.*.jpg$/).match(file)} if File.exist?(image_path)
  Dir.foreach(audio_path){|file| File.delete(audio_path+file) if (/^.*.wav$/).match(file)} if File.exist?(audio_path)
  puts "Captcha files removed."
end

You can confirm that task is added to your app by running
rake –task

To remove all the files created by captcha, simply run the command
rake remove_captcha_files
from the command line from your application root.
To better view the code visit here

Advertisements

Entry filed under: rake, Ruby on Rails.

Translate Your Rails Application. How to improve the image quality and generate random string image in the plugin validates_captcha

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


Contact

sur.max(at)gmail.com
October 2006
M T W T F S S
« Sep   Nov »
 1
2345678
9101112131415
16171819202122
23242526272829
3031  

Power Shots

Subscribe


%d bloggers like this: