While working with a multiple-database application I came across the point where I had to juggle between different environment configurations.
I had to pass connection hash to ActiveRecord::Base.establish_connection, something like this:
ActiveRecord::Base.establish_connection ( :adapter=>"mysql", :host=>"localhost", :username=>"myuser", :password=>"mypass", :database => "somedatabase" )
This connection can be easily retrieved from ActiveRecord::Base.configurations, this is currently undocumented.
Using ActiveRecord::Base.configurations, the above can be simply written as:
ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations['production'])
1 response so far ↓
akhil // October 10, 2008 at 12:25 pm |
Good catch rishav