Database connection per model

I’ve built database authentication into my app, however once they’re
authenticated all their actions are done under the default user account
setup in database.yml. I would like to establish a database connection
in each model (so that all actions can be audited under the users’
database accounts). My hang-up is trying to pass the session username
and password into the establish_connection call. I know the model can’t
access session parameters, so was wondering if there’s another way. I
know establishing database connection in the code isn’t best
practice…so any other suggestions to accomplish this are also welcome.
Thanks in advance.

On Feb 1, 8:48 pm, Brian P. [email protected]
wrote:

I know the model can’t
access session parameters, so was wondering if there’s another way.

Maybe I’m being thick here, but why can’t session parameters
available in the controller be sent to the model to establish the
connection?

I had models that have to change the database connection, depending on
parameters passed to the controller action, so I’m mystified why that
can’t happen for you! Mind you, sessions are something I have yet to
tackle properly!

Allan

Allan wrote:

On Feb 1, 8:48 pm, Brian P. [email protected]
wrote:

I know the model can’t
access session parameters, so was wondering if there’s another way.

Maybe I’m being thick here, but why can’t session parameters
available in the controller be sent to the model to establish the
connection?

I had models that have to change the database connection, depending on
parameters passed to the controller action, so I’m mystified why that
can’t happen for you! Mind you, sessions are something I have yet to
tackle properly!

Allan

Work
around…http://www.zorched.net/2007/05/29/making-session-data-available-to-models-in-ruby-on-rails/

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs