Sounds to me like you want two DB connections, one for each
user. Use the session variable to choose which connection to
use. Multiple connections to one db should be equivalent to
connecting to multiple
Yes, that's what I want to do, but this doesn't seem to be a common
practice, or at least a well-documented common practice. I'll see what I
can do to help fix the latter.
It would seem the pragmatic thing to do would be to define a parallel
set of database targets in database.yml (admin_development,
admin_production, etc.) and in the admin controllers, using a
before_filter, call ActiveRecord::Base.establish_connection with the
admin users' credentials. Three questions come up:
1. Can I access the rails Configuration object at request-time? I mean,
I could parse database.yml manually, but that's redundant. Alternately,
I could store a reference to the Configuration object in environment.rb.
2. If I manually call ActiveRecord::Base.establish_connection, should I
close the original connection first? Should I close the newly created
connection myself in an after_filter? What should I do in case of
3. Do the answers vary depending on if I running in a FastCGI, CGI, or
Any tips are greatly appreciated. Any pointers towards comprehensive
documentation of the rails' application and requests lifecycles would be
helpful too. Cheers.