Created
July 8, 2010 16:35
-
-
Save RainerBlessing/468272 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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