I have two Heroku apps, one for staging, one for production. Each has its own separate, primary DB. I have a 2nd Heroku DB that needs to be accessed by both staging and production.
Running Rails 4.1.0.rc1, when I try to use 'establish_connection' and a URL I've configured with all the correct values for the secondary DB, I end up connecting to the primary DB instead. Afterwards, if I examine ActiveRecord::Base.configurations, I see a new key/value pair that's been added. The key is the URL and the value appears to be a copy of the configuration values for the 'production' key.
All my research indicates that all I need to do is
User.establish_connection ENV['SECONDARY_DATABASE_URL']
This method works fine, locally, but fails on Heroku.