diff --git a/lib/recaptcha.rb b/lib/recaptcha.rb index 59329324..babef024 100644 --- a/lib/recaptcha.rb +++ b/lib/recaptcha.rb @@ -1,9 +1,14 @@ require 'recaptcha/configuration' -require 'recaptcha/client_helper' -require 'recaptcha/verify' require 'uri' require 'net/http' +if defined?(Rails) + require 'recaptcha/railtie' +else + require 'recaptcha/client_helper' + require 'recaptcha/verify' +end + module Recaptcha CONFIG = { 'server_url' => 'https://www.google.com/recaptcha/api.js', diff --git a/lib/recaptcha/rails.rb b/lib/recaptcha/rails.rb deleted file mode 100644 index b00748f5..00000000 --- a/lib/recaptcha/rails.rb +++ /dev/null @@ -1,10 +0,0 @@ -require 'recaptcha' - -module Recaptcha - class Railtie < Rails::Railtie - initializer :recaptcha do - ActionView::Base.send(:include, ::Recaptcha::ClientHelper) - ActionController::Base.send(:include, ::Recaptcha::Verify) - end - end -end diff --git a/lib/recaptcha/railtie.rb b/lib/recaptcha/railtie.rb new file mode 100644 index 00000000..0bce011a --- /dev/null +++ b/lib/recaptcha/railtie.rb @@ -0,0 +1,15 @@ +module Recaptcha + class Railtie < Rails::Railtie + initializer :recaptcha do + ActiveSupport.on_load(:action_view) do + require 'recaptcha/client_helper' + include Recaptcha::ClientHelper + end + + ActiveSupport.on_load(:action_controller) do + require 'recaptcha/verify' + include Recaptcha::Verify + end + end + end +end