support for multiple database session

Hi all,

I am working on a rails project. First I am giving a brief of what it does then I will tell what are issues I am facing.

This project is basically a reporting tool that gets data from database and generates report. I have different databases for different products with same structure (schema) for all. I want to have a drop down menu on the homepage where user can select which database he wants to connect and generate report for the selected database. I am connecting to selected database manually in application controller and using this as before_filter in application.rb.

Problem is that user can select any database while logs in. When two users log in selecting different databases. The user who logs in later only database session for that user sustains and data from other database no longer accessible to user logged in first. Rather he also now gets data of 2nd database.

I must implement it correctly. Please suggest me how it can be done. I have 5 such databases to connect dynamically with each user always gets data from selected database.

Thanks a lot, Nitin.