From c62f7b4b7ca9e16c7dace09b4083af3e5a793410 Mon Sep 17 00:00:00 2001 From: Nick Hengeveld Date: Wed, 20 Oct 2010 09:33:36 -0700 Subject: [PATCH 1/4] Fix make_tmpname issue with Ruby 1.9.2 --- lib/simple_captcha/image.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/simple_captcha/image.rb b/lib/simple_captcha/image.rb index 62deed5..81c45c7 100755 --- a/lib/simple_captcha/image.rb +++ b/lib/simple_captcha/image.rb @@ -48,6 +48,7 @@ class Tempfile < ::Tempfile # Replaces Tempfile's +make_tmpname+ with one that honors file extensions. def make_tmpname(basename, n) extension = File.extname(basename) + n ||= 0 sprintf("%s,%d,%d%s", File.basename(basename, extension), $$, n, extension) end end From 3c31f5dca8bab2ed718a5371ae107a49646feb93 Mon Sep 17 00:00:00 2001 From: Nick Hengeveld Date: Wed, 20 Oct 2010 09:34:02 -0700 Subject: [PATCH 2/4] Allow user-specified :size for captcha text field --- lib/simple_captcha/form_builder.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/simple_captcha/form_builder.rb b/lib/simple_captcha/form_builder.rb index 4bec7a7..8624f7e 100644 --- a/lib/simple_captcha/form_builder.rb +++ b/lib/simple_captcha/form_builder.rb @@ -26,7 +26,9 @@ def template end def simple_captcha_field(options={}) - text_field(:captcha, :value => '', :autocomplete => 'off') + + text_field_options = {:value => '', :autocomplete => 'off'} + text_field_options[:size] = options[:size] unless options[:size].nil? + text_field(:captcha, text_field_options) + hidden_field(:captcha_key, {:value => options[:field_value]}) end end From 341c04370280a1a7e61f49931fbb899b8017a6fb Mon Sep 17 00:00:00 2001 From: Nick Hengeveld Date: Thu, 21 Oct 2010 17:31:01 -0700 Subject: [PATCH 3/4] Add X-Accel-Redirect header for nginx --- app/controllers/simple_captcha_controller.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/simple_captcha_controller.rb b/app/controllers/simple_captcha_controller.rb index 4358c32..0d7770e 100644 --- a/app/controllers/simple_captcha_controller.rb +++ b/app/controllers/simple_captcha_controller.rb @@ -5,8 +5,10 @@ class SimpleCaptchaController < ActionController::Metal # GET /simple_captcha def show unless params[:id].blank? + image_file = generate_simple_captcha_image(params[:id]) + response.headers['X-Accel-Redirect'] = image_file send_file( - generate_simple_captcha_image(params[:id]), + image_file, :type => 'image/jpeg', :disposition => 'inline', :filename => 'simple_captcha.jpg') From a2789153422c672faf15841abb20283d423135c2 Mon Sep 17 00:00:00 2001 From: Nick Hengeveld Date: Thu, 21 Oct 2010 17:55:50 -0700 Subject: [PATCH 4/4] Captcha images are small, try send_data instead of send_file + X-Accel-Redirect --- app/controllers/simple_captcha_controller.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/controllers/simple_captcha_controller.rb b/app/controllers/simple_captcha_controller.rb index 0d7770e..62a8afa 100644 --- a/app/controllers/simple_captcha_controller.rb +++ b/app/controllers/simple_captcha_controller.rb @@ -5,10 +5,9 @@ class SimpleCaptchaController < ActionController::Metal # GET /simple_captcha def show unless params[:id].blank? - image_file = generate_simple_captcha_image(params[:id]) - response.headers['X-Accel-Redirect'] = image_file - send_file( - image_file, + image = File.read generate_simple_captcha_image(params[:id]) + send_data( + image, :type => 'image/jpeg', :disposition => 'inline', :filename => 'simple_captcha.jpg')