# Current User, Database etc

**URL:** <https://www.ruby-forum.com/t/current-user-database-etc/169850>\
**Category:** Rails\
**Created:** [June 9, 2009, 4:14pm UTC](https://www.ruby-forum.com/t/current-user-database-etc/169850 "2009-06-09T16:14:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![stevedogers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9dc877/32.png) [@stevedogers](https://www.ruby-forum.com/u/stevedogers)\
**Post date:** [June 9, 2009, 4:14pm UTC](https://www.ruby-forum.com/t/current-user-database-etc/169850/1 "2009-06-09T16:14:14Z")

</div>

Are there methods for the model object to get the current\_user, and  
current\_database? I was hoping that this would be available as methods  
from the connection object.

For example  
model.connection.db\_user  
model.connection.db\_name

Is there a group for ActiveRecord, where I can post this?

---

<div class="post-metadata">

**Author:** ![stevedogers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9dc877/32.png) [@stevedogers](https://www.ruby-forum.com/u/stevedogers)\
**Post date:** [June 9, 2009, 4:20pm UTC](https://www.ruby-forum.com/t/current-user-database-etc/169850/2 "2009-06-09T16:20:49Z")

</div>

YourActiveRecordModel.configurations[Rails.env][‘username’]  
YourActiveRecordModel.configurations[Rails.env][‘database’]

- 

Maurício Linhares  
[http://codeshooter.wordpress.com/](http://codeshooter.wordpress.com/) | [http://twitter.com/mauriciojr](http://twitter.com/mauriciojr)

On Tue, Jun 9, 2009 at 11:14 AM, Steve

---

<div class="post-metadata">

**Author:** ![stevedogers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9dc877/32.png) [@stevedogers](https://www.ruby-forum.com/u/stevedogers)\
**Post date:** [June 9, 2009, 5:26pm UTC](https://www.ruby-forum.com/t/current-user-database-etc/169850/3 "2009-06-09T17:26:24Z")

</div>

MaurÃ­cio Linhares wrote:

> YourActiveRecordModel.configurations[Rails.env][‘username’]  
> YourActiveRecordModel.configurations[Rails.env][‘database’]
> 
> - 
> 
> Maurï¿½cio Linhares  
> [http://codeshooter.wordpress.com/](http://codeshooter.wordpress.com/) | [http://twitter.com/mauriciojr](http://twitter.com/mauriciojr)
> 
> On Tue, Jun 9, 2009 at 11:14 AM, Steve

Thanks for your suggestion. However I am spcifying a dsn which includes  
Username, and database. This approach has a couple of issues.

1. The user may be logging in using Windows authentication. In that case  
database.yml will not have a value for User field.
2. What if the application changes connection after starting up?

---

<div class="post-metadata">

**Author:** ![stevedogers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9dc877/32.png) [@stevedogers](https://www.ruby-forum.com/u/stevedogers)\
**Post date:** [June 9, 2009, 6:50pm UTC](https://www.ruby-forum.com/t/current-user-database-etc/169850/4 "2009-06-09T18:50:45Z")

</div>

This is how you can get the info from an activerecord object, if  
you’re not using active record or if you’re using a custom made  
solution it obviously won’t work.

- 

MaurÃ­cio Linhares  
[http://codeshooter.wordpress.com/](http://codeshooter.wordpress.com/) | [http://twitter.com/mauriciojr](http://twitter.com/mauriciojr)

On Tue, Jun 9, 2009 at 12:26 PM, Steve
