Ultimately what I need to make happen is have two domains point to the same application, however depending on which domain is accessing it to use a different database. I suggested installing the application on two servers, but that option is for some reason not good. I tried to install the application twice into one account and just symlink them depending on the domain but that did not work either, here''s why: One domain has to point to ~/public_html, I have no option in that the way our host is set up. The second domain has to point to a subdirectory of ~/public_html. Adding a symlink to the first application''s public folder didn''t work because Apache is unable to follow through two symlinks. Adding any extra characters to the URL is out of the question too, so I can''t use domain.com/i/app Ultimately I just need the question answered that is at the top, any takers? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
perhaps one way is to build your models like so: class MyModel < ActiveRecord::Base establish_connection( :adapter => "whatever", :host => "database_#{request.host.gsub(/[^w], ''_'')}", :username => ''user'', :password => ''pass'' ) end beware i have not tested this, so i''m not sure if this would run with every model instantiation and if the above works, maybe a DRY optimization would be to stuff it into ActiveRecord::Base once instead of every model On Apr 17, 5:03 pm, jawgaping <jawgap...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Ultimately what I need to make happen is have two domains point to the > same application, however depending on which domain is accessing it to > use a different database. > > I suggested installing the application on two servers, but that option > is for some reason not good. I tried to install the application twice > into one account and just symlink them depending on the domain but > that did not work either, here''s why: > > One domain has to point to ~/public_html, I have no option in that the > way our host is set up. The second domain has to point to a > subdirectory of ~/public_html. Adding a symlink to the first > application''s public folder didn''t work because Apache is unable to > follow through two symlinks. > > Adding any extra characters to the URL is out of the question too, so > I can''t use domain.com/i/app > > Ultimately I just need the question answered that is at the top, any > takers?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Apr 17, 2007, at 11:03 PM, jawgaping wrote:> Ultimately what I need to make happen is have two domains point to the > same application, however depending on which domain is accessing it to > use a different database. > > I suggested installing the application on two servers, but that option > is for some reason not good. I tried to install the application twice > into one account and just symlink them depending on the domain but > that did not work either, here''s why: > > One domain has to point to ~/public_html, I have no option in that the > way our host is set up. The second domain has to point to a > subdirectory of ~/public_html. Adding a symlink to the first > application''s public folder didn''t work because Apache is unable to > follow through two symlinks. > > Adding any extra characters to the URL is out of the question too, so > I can''t use domain.com/i/app > > Ultimately I just need the question answered that is at the top, any > takers?What about having two separate checkouts in the same machine, each with its own database.yml. Configure a virtual host for each one in Apache. Each virtual host then has its own document root and mongrel cluster (each instance of the application runs behind its own cluster). -- fxn --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Although a low level solution would be more preferable, this works wonderfully! Thank you jemm you probably saved my job. On Apr 17, 2:13 pm, jemminger <jemmin...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> perhaps one way is to build your models like so: > > class MyModel < ActiveRecord::Base > establish_connection( > :adapter => "whatever", > :host => "database_#{request.host.gsub(/[^w], ''_'')}", > :username => ''user'', > :password => ''pass'' > ) > end > > beware i have not tested this, so i''m not sure if this would run with > every model instantiation > > and if the above works, maybe a DRY optimization would be to stuff it > into ActiveRecord::Base once instead of every model > > On Apr 17, 5:03 pm, jawgaping <jawgap...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Ultimately what I need to make happen is have two domains point to the > > same application, however depending on which domain is accessing it to > > use a different database. > > > I suggested installing the application on two servers, but that option > > is for some reason not good. I tried to install the application twice > > into one account and just symlink them depending on the domain but > > that did not work either, here''s why: > > > One domain has to point to ~/public_html, I have no option in that the > > way our host is set up. The second domain has to point to a > > subdirectory of ~/public_html. Adding a symlink to the first > > application''s public folder didn''t work because Apache is unable to > > follow through two symlinks. > > > Adding any extra characters to the URL is out of the question too, so > > I can''t use domain.com/i/app > > > Ultimately I just need the question answered that is at the top, any > > takers?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Apr 18, 2007, at 2:51 AM, jawgaping wrote:> > Although a low level solution would be more preferable, this works > wonderfully! Thank you jemm you probably saved my job. > > > On Apr 17, 2:13 pm, jemminger <jemmin...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> perhaps one way is to build your models like so: >> >> class MyModel < ActiveRecord::Base >> establish_connection( >> :adapter => "whatever", >> :host => "database_#{request.host.gsub(/[^w], ''_'')}", >> :username => ''user'', >> :password => ''pass'' >> ) >> endCareful, with that approach MyModel will always point to the database of the domain that triggered its class loading. In development mode that works because the class is reloaded at each request. However, in production mode that means MyModel won''t point to the table of the database of the other domain _ever_. If that''s OK then you have your model layer really partitioned in two databases known before hand, and in that case the regular establish_connection + two keys in database.yml will suffice. Otherwise you''d move that code to a high-priority filter in ApplicationController: def choose_database_for_host ActiveRecord::Base.establish_connection ... end because you need to select the connection _per request_. That has a performance cost, but perhaps it''s fine with the load of that applicaction. If that was not the case more intrusive solutions involving some sort of connection pool would be needed. -- fxn PS: The solution with two separate checkouts with respective mongrel clusters didn''t fit? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---