[Rails] Accessing Session Object from a model
スタン マズレック
smazurek at doubleclick.ne.jp
Mon Mar 27 12:49:01 GMT 2006
Well, that works but only if i want to globally switch db's between users.
The thing is, i need to access a common USER table, and then switch to
separate dbs..
Stan
Dee Zsombor wrote:
>スタン マズレック wrote:
>
>
>>Basically, we have a product where each customer has their own profile
>>with data stored in a separate database. There are some tables in a
>>common 'system-wide' database such as the user, role & permission
>>tables, but a lot of other stuff has to be divided up into separate DBs
>>per customer. I realise this isn't the best way to organise the data but
>>it's a requirement of the project so i'm stuck with it.
>>
>>
>
>Try using a before_filter in your controller:
>
>before_filter :establish_per_user_db_connection
>
>def establish_per_user_db_connection
> Report.establish_connection(
> :adapter => MyConfig.config(:db_adaptor),
> :username => MyConfig.config(:db_user_name),
> :password => MyConfig.config(:db_password),
> :database => @session[:user].profile.name + "_dbname")
>end
>
>
>Zsombor
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060327/6ed5512d/attachment-0001.html
More information about the Rails
mailing list