Forum: Ruby on Rails Re: multiple database users for rails app?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
E1f43bafda26307a050d11902752b2a6?d=identicon&s=25 Ball, Donald A Jr (Library) (Guest)
on 2007-01-23 19:09
(Received via mailing list)
> 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
> databases:

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.
Any suggestions?

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
Mongrel environment?

Any tips are greatly appreciated. Any pointers towards comprehensive
documentation of the rails' application and requests lifecycles would be
helpful too. Cheers.

- doald
This topic is locked and can not be replied to.