# Login chooses database

**URL:** <https://www.ruby-forum.com/t/login-chooses-database/164111>\
**Category:** Rails\
**Created:** [March 28, 2009, 1:15am UTC](https://www.ruby-forum.com/t/login-chooses-database/164111 "2009-03-28T01:15:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rike](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b782af/32.png) [@rike](https://www.ruby-forum.com/u/rike)\
**Post date:** [March 28, 2009, 1:15am UTC](https://www.ruby-forum.com/t/login-chooses-database/164111/1 "2009-03-28T01:15:25Z")

</div>

Hi,

I just finishes my first RoR application and I’m happy that nearly every  
problem I had was solved. But now I need your help. The problem is that  
an other organisation wants to use my application as well. The server  
will stay the same, but the want to have a seperate database (with the  
same structure as the first one). I don’t want to copy my  
application-files because this would be very unpractible for the further  
development.  
Unfortunately I have no idea how to realize this. May I put in a  
selection field to the loginform, where the user chooses his  
organisation? Is it possible that useres of different organisation work  
at the same time with the apllication with different databases? Is there  
a possibility with the session?  
I treasure every hint!

Thanks a lot

Rike

---

<div class="post-metadata">

**Author:** ![rike](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b782af/32.png) [@rike](https://www.ruby-forum.com/u/rike)\
**Post date:** [March 28, 2009, 9:23am UTC](https://www.ruby-forum.com/t/login-chooses-database/164111/2 "2009-03-28T09:23:33Z")

</div>

How about using a single Rails app and configuring your apache or  
webserver to point two domain names to the same application. Then,  
based on the domain in the login request, you can determine how to  
authenticate your user.

On your “User” model, would associate each user with a domain (ex.  
domain1 or domain2) which would govern business logic depending on  
the user.

On Mar 27, 5:15 pm, Rike H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![rike](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b782af/32.png) [@rike](https://www.ruby-forum.com/u/rike)\
**Post date:** [March 28, 2009, 8:12pm UTC](https://www.ruby-forum.com/t/login-chooses-database/164111/3 "2009-03-28T20:12:03Z")

</div>

> I just finishes my first RoR application

Good for you. And now someone else wants to use it, even better!

As to how to do this, one reliable way to do this is to use version  
control and capistrano.

version control  
If you have not added your code base to a version control repository,  
now is the time to do this. Whether you choose to use subversion or  
git, setup a server in your environment to keep incremental changes to  
your application there. Version control gives you the ability to name  
your versions.

capistrano  
once you have your repository, you “deploy” new versions of your  
application to any number of servers. In this case, you have two  
“users” of your app. So whether the apps are housed on the same  
server, or two servers, you use capistrano to write  
“recipes” (scripts) to deploy to the target servers.

It is a proven, scalable way of doing what you want. Then, anytime  
something changes, as it always happens, you have the choice to apply  
your changes to one or both apps, and affect one or the two databases.  
Keeps things under control.

Good luck, and congrats again.

---

<div class="post-metadata">

**Author:** ![rike](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b782af/32.png) [@rike](https://www.ruby-forum.com/u/rike)\
**Post date:** [March 29, 2009, 12:30am UTC](https://www.ruby-forum.com/t/login-chooses-database/164111/4 "2009-03-29T00:30:00Z")

</div>

Thanks a lot for your good tipps! This means I have to copy the whole  
application to f.e. a subdomain? So if 3 other organisations want to use  
this application I copy the whole code three times? Ok. So when I have a  
new version then capsitrano helps me to update the other apps? Right?  
… I think this will be a not trivial job…  
I know git a (very) little bit. It seems that I have to go in with this.  
🙂 So, thank you again - I will try this.
