Forum: Ruby on Rails same code different databases?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Simon S. (Guest)
on 2009-05-15 17:02
(Received via mailing list)
Hello,

We want to serve multiple clients using the same logic but having a
separate database for each client. We are using capistrano to deploy
our web application. Anybody has any idea how we could do this? Thanks!
Simon S. (Guest)
on 2009-05-15 18:34
(Received via mailing list)
I'm using a different subdomain for each tenant, so could we choose
the database in rails depending on the subdomain?
Simon S. (Guest)
on 2009-05-18 20:48
(Received via mailing list)
Anybody =/
Frederick C. (Guest)
on 2009-05-18 22:13
(Received via mailing list)
On 18 May 2009, at 17:47, Kentor wrote:

>
> Anybody =/
>
you could try calling ActiveRecord::Base.establish_connection from a
before_filter. Re-establishing connections like that every request
might be horribly slow.

Fred
Simon S. (Guest)
on 2009-05-22 16:17
(Received via mailing list)
Hello,

I followed this great guide at
http://magicmodels.rubyforge.org/magic_multi_connections
.

This guide works perfectly for one model. But I think if I were to use
it for another one, I would have to duplicate the code for each
model...
For my subdomain problem, the way I think it should be done is have a
global function which will run for all objects, look at the subdomain
and set the connection but I'm not sure where to put what piece of
code to achieve this.

Also, when I applied the guide (http://magicmodels.rubyforge.org/
magic_multi_connections) to an existing application (http://
guides.rubyonrails.org/getting_started.html -> it is a guide to create
a blog) it would work perfectly but only if I comment these lines out:

            #link_to 'Show', post
            #link_to 'Edit', edit_post_path(post)
            #link_to 'Destroy', post, :confirm => 'Are you
sure?', :method => :delete

otherwise, if the connection is other than default and the 1st or 3rd
line is present I get a this:

undefined method `private_testing_post_path' for #<ActionView::Base:
0x6b08550>

I used the name "Module PrivateTesting" instead of "Module Private"...

I'm pretty sure there is an obvious fix for my problem (either the
subdomain or the one with the errors I'm getting and maybe I will be
able to figure it out from there) but I'm new to Rails and I've spent
many hours trying to get this to work without any success. Any help
would be really really appreciated. Thank you!

On May 18, 2:12 pm, Frederick C. <removed_email_address@domain.invalid>
This topic is locked and can not be replied to.