Is it thread safe to set Active Resource HTTP authentication on a per-user basis?

Monkey patch the host, user and password methods of ActiveResource::Base class: class ActiveResource::Base # store the attribute value in a thread local variable class << self %w(host user password).each do |attr| define_method(attr) do Thread.current[“active_resource.#{attr}”] end define_method(“#{attr}=”) do |val| Thread.current[“active_resource.#{attr}”] = val end end end end Now set the credentials in every request class ApplicationController < … Read more

Connecting Rails 3.1 with Multiple Databases

To Wukerplank’s answer, you can also put the connection details in database.yml like usual with a name like so: log_database_production: adapter: mysql host: other_host username: logmein password: supersecret database: logs Then in your special model: class AccessLog < ActiveRecord::Base establish_connection “log_database_#{Rails.env}”.to_sym end To keep those pesky credentials from being in your application code. Edit: If … Read more