Skip to content

Instantly share code, notes, and snippets.

@RainerBlessing
Created July 8, 2010 16:35
Show Gist options
  • Save RainerBlessing/468272 to your computer and use it in GitHub Desktop.
Save RainerBlessing/468272 to your computer and use it in GitHub Desktop.
diff --git a/lib/foreigner.rb b/lib/foreigner.rb
index 540657a..2eb55aa 100644
--- a/lib/foreigner.rb
+++ b/lib/foreigner.rb
@@ -19,6 +19,14 @@ module Foreigner
end
def configured_adapter
+ if !ActiveRecord::Base.connected?
+ if Rails.application
+ ActiveRecord::Base.configurations = Rails.application.config.database_configuration
+ ActiveRecord::Base.establish_connection
+ ActiveRecord::Base.connection.adapter_name.downcase
+ end
+ else
+ ActiveRecord::Base.connection.adapter_name.downcase
+ end
- ActiveRecord::Base.connection.adapter_name.downcase
end
@@ -26,8 +34,10 @@ module Foreigner
if defined?(Rails) && Rails.version >= '3.0'
ActiveSupport.on_load :active_record do
unless ActiveRecord::Base.connected?
- ActiveRecord::Base.configurations = Rails.application.config.database_configuration
- ActiveRecord::Base.establish_connection
+ if Rails.application
+ ActiveRecord::Base.configurations = Rails.application.config.database_configuration
+ ActiveRecord::Base.establish_connection
+ end
end
block.call
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment