I know that it's possible to use multiple databases with Rails.
However most of the examples I have seen were for high availability. I
would like to learn if anyone has any experience with a shared
database among many rails applications. Such a case may make sense for
shared user information. Any ideas?
We use one database for a shared application which includes an ecommerce site, the associated admin site, and the orders site.
All you have to do is make sure your database.yml files match, and be sure to copy your models into each site. It works well, but....
It really violates the DRY principle. I'm not sure why our sites were set up like this, but the more I use it the more irritated I get when I run into an error because I didn't copy a model from site to site.
If you can figure out how to get past this, or it doesn't apply, then using one database shared between sites isn't too big of a deal.
You could put your models and other shared parts of all these
applications in a plugin in a seperate repository and include that
plugin in your applications through svn:externals. That way, whenever
you deploy your apps, svn pulls the most recent versions of your
shared files.
This feature is implemented by keeping a connection pool in ActiveRecord::Base that is a Hash indexed by the class. If a connection is requested, the retrieve_connection method will go up the class-hierarchy until a connection is found in the connection pool.
What about creating a rails application to act as an authentication
service? Then use ActiveResource to authenticate your users from each
of your applications in place of ActiveRecord? I think that's the
approach I would take. Another option would be to use an LDAP server
for storing and authenticating users.
In other words use a Single Sign On (SSO) approach to authentication.
Another really good option would be to implement OpenID and forego the
whole username/password combination all together. I for one will be
very happy once the world really catches onto this. To have one single
source of identity for every site I use would be fantastic.
Just some ideas to think about. Either of these methods would be DRY
and very flexible.