Gianluca Tessarolo
2007-Oct-31 10:33 UTC
Question for rails multidomain application design
Hi to all, I would design an application for multidomain support and my question is what is the best practice to do this kind of application ? Eg.: I think to write my application handling the multidomain into routing map: map.connect ":domain/:controller/:action" map.connect ":domain/:controller/:action/:id" Assuming that I hanlde 3 domains for 3 different customers: www.first.com www.second.com www.third.com My customers requests could be: http://www.first.com/public/home http://www.second.com/public/home http://www.third.com/public/home routed to RoR application: /www.first.com/public/home /www.second.com/public/home /www.third.com/public/home RoR application controller could read the home data from model finding by domain param (es. @home = Home.find_by_domain(params[:domain]) I would like to know if it is possible (and how can I solve) this kind of routing (maybe using Apache internal rewrite ?). Thanks in advance ! ... --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Gianluca Tessarolo
2007-Oct-31 16:13 UTC
Question for rails multidomain application design
Hi to all, I would design an application for multidomain support and my question is what is the best practice to do this kind of application ? Eg.: I think to write my application handling the multidomain into routing map: map.connect ":domain/:controller/:action" map.connect ":domain/:controller/:action/:id" Assuming that I hanlde 3 domains for 3 different customers: www.first.com www.second.com www.third.com My customers requests could be: http://www.first.com/public/home http://www.second.com/public/home http://www.third.com/public/home routed to RoR application: /www.first.com/public/home /www.second.com/public/home /www.third.com/public/home RoR application controller could read the home data from model finding by domain param (es. @home = Home.find_by_domain(params[:domain]) I would like to know if it is possible (and how can I solve) this kind of routing (maybe using Apache internal rewrite ?). Thanks in advance ! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
KathysKode-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Nov-01 12:32 UTC
Re: Question for rails multidomain application design
Gianluca, I approached the same proble by using the domain as a unique :id and ''scoping'' the entire database based on the incoming request.host. Kathy On Oct 31, 10:13 am, Gianluca Tessarolo <tessarolo.gianl...-6ZZdBs7hMehZp5Udy/Obhg@public.gmane.org> wrote:> Hi to all, > > I would design an application for multidomain support and my question is > what is the best practice to do this kind of application ? > > Eg.: > > I think to write my application handling the multidomain into routing map: > > map.connect ":domain/:controller/:action" > map.connect ":domain/:controller/:action/:id" > > Assuming that I hanlde 3 domains for 3 different customers: > > www.first.comwww.second.comwww.third.com > > My customers requests could be: > > http://www.first.com/public/homehttp://www.second.com/public/homehttp://www.third.com/public/home > > routed to RoR application: > > /www.first.com/public/home > /www.second.com/public/home > /www.third.com/public/home > > RoR application controller could read the home data from model finding > by domain param (es. @home = Home.find_by_domain(params[:domain]) > > I would like to know if it is possible (and how can I solve) this kind > of routing (maybe using Apache internal rewrite ?). > > Thanks in advance !--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Pablo Castellazzi
2007-Nov-01 18:02 UTC
Re: Question for rails multidomain application design
Why not something like this instead? class ApplicationController < ActionController::Base before_filter :setup_application_by_domain protected def setup_application_by_domain @domain = Domain.find_by_name(request.domain) # continue with your setup end end The mapping idea, can be a little messy, specialy if you forgot to map an action, i think it''s better to get the domain information from the request object, and setup an instance of some model with all the information you need. On Oct 31, 10:13 am, Gianluca Tessarolo <tessarolo.gianl...-6ZZdBs7hMehZp5Udy/Obhg@public.gmane.org> wrote:> Hi to all, > > I would design an application for multidomain support and my question is > what is the best practice to do this kind of application ? > > Eg.: > > I think to write my application handling the multidomain into routing map: > > map.connect ":domain/:controller/:action" > map.connect ":domain/:controller/:action/:id" > > Assuming that I hanlde 3 domains for 3 different customers: > > www.first.comwww.second.comwww.third.com > > My customers requests could be: > > http://www.first.com/public/homehttp://www.second.com/public/homehttp://www.third.com/public/home > > routed to RoR application: > > /www.first.com/public/home > /www.second.com/public/home > /www.third.com/public/home > > RoR application controller could read the home data from model finding > by domain param (es. @home = Home.find_by_domain(params[:domain]) > > I would like to know if it is possible (and how can I solve) this kind > of routing (maybe using Apache internal rewrite ?). > > Thanks in advance !--~--~---------~--~----~------------~-------~--~----~ 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 Oct 31, 2007, at 9:13 AM, Gianluca Tessarolo wrote:> I would design an application for multidomain support and my > question is > what is the best practice to do this kind of application ? > > My customers requests could be: > > http://www.first.com/public/home > http://www.second.com/public/home > http://www.third.com/public/homeI haven''t done this in Rails yet, but I''ve written several multi- domain (multi-subdomain) apps in another language, and IMO it is best to initialize an object as one of your first steps (so withing application.rb) which contains the baseline info the app needs: domain name, layout preferences, options features if applicable, etc. So, take all those configuration details you might otherwise have in code, and push them into a db. Then the first task you do is querythe db for the config details for X domain or subdomain. From that point on your app is really like any single-domain app except that you use the domain name to identify a specific database if you use a db per domain, or it defines how you filter all db queries if you use one db for all domains. It really is easier than it usually first sounds like. From what I can tell, even in Rails, there''s no need to map domain to a route because the domain won''t change the actual actions you''re calling. You want the actions themselves to adjust their behavior based on domain which is no different than having them change based on a specific logged in user. So, just like you would not change routes based on users, you don''t need to do it based on domains. Make sense? -- gw --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Gianluca Tessarolo
2007-Nov-06 09:54 UTC
Re: Re: Question for rails multidomain application design
Thanks Kathy, Pablo and Greg, u r right. Your suggestions was very good and drive me into right direction, I solved the problem only setting 3 virtual hosts pointing to the same rails app and simply setting the base application controller filter (no routing map at all !): @domain = Domain.find_by_name(request.domain) Last question: How did u solve the different public folder for each domain ? In my application static contents must be separated for each different domain www.first.com / www.second.com / www.third.com so I think I must have 3 different public folder, one for each different domain ? How can handle this into rails application ? (one possible solution is to handle a parameter for images and stylesheets ":path" but I think there is a better solution because in this case I have to use tha ":path" parameter into each view...). Thanks in advance... -- Gianluca Tessarolo TreNetMediaMaster S.r.l. The Internet Technology Company Telefono +39(049)776196 Fax +39(049)8087806 Visit us @: http://www.trenet.it - http://www.mediamaster.it e-mail me @: tessarolo.gianluca-6ZZdBs7hMehZp5Udy/Obhg@public.gmane.org ---------------------------------------------------------------------- Le informazioni trasmesse sono destinate esclusivamente alla persona o alla società in indirizzo e sono da intendersi confidenziali e riservate. Ogni trasmissione, inoltro, diffusione o altro uso di queste informazioni a persone o società differenti dal destinatario é proibita. Se ricevete questa comunicazione per errore, contattate il mittente e cancellate le informazioni da ogni computer. --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
KathysKode-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Nov-06 15:06 UTC
Re: Question for rails multidomain application design
Gianluca, Once you''ve learned to ''scope'' the @domain table based on the current request.domain the rest is downhill. If I had a table called ''content'' I''d use the before filter to find the domain and then gather the collection like; @content = @domain.contents.find(:all) and so on for any table in your application. Kathleen On Nov 6, 3:54 am, Gianluca Tessarolo <tessarolo.gianl...-6ZZdBs7hMehZp5Udy/Obhg@public.gmane.org> wrote:> Thanks Kathy, Pablo and Greg, u r right. > > Your suggestions was very good and drive me into right direction, > > I solved the problem only setting 3 virtual hosts pointing to the same > rails app and simply setting the base application controller filter (no > routing map at all !): > > @domain = Domain.find_by_name(request.domain) > > Last question: > > How did u solve the different public folder for each domain ? > > In my application static contents must be separated for each different > domainwww.first.com/www.second.com/www.third.comso I think I must > have 3 different public folder, one for each different domain ? > > How can handle this into rails application ? (one possible solution is > to handle a parameter for images and stylesheets ":path" but I think > there is a better solution because in this case I have to use tha > ":path" parameter into each view...). > > Thanks in advance... > > -- > Gianluca Tessarolo > TreNetMediaMaster S.r.l. > The Internet Technology Company > Telefono +39(049)776196 > Fax +39(049)8087806 > Visit us @:http://www.trenet.it-http://www.mediamaster.it > e-mail me @: tessarolo.gianl...-6ZZdBs7hMehZp5Udy/Obhg@public.gmane.org > ---------------------------------------------------------------------- > Le informazioni trasmesse sono destinate esclusivamente alla persona o > alla società in indirizzo e sono da intendersi confidenziali e riservate. > Ogni trasmissione, inoltro, diffusione o altro uso di queste > informazioni a persone o società differenti dal destinatario é proibita. > Se ricevete questa comunicazione per errore, contattate il mittente e > cancellate le informazioni da ogni computer.--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Gianluca Tessarolo
2007-Nov-06 15:41 UTC
Re: Re: Question for rails multidomain application design
Hi Kathleen, thank you very much for your reply ! Thanks to your suggestion I solved the problem for accessing "dynamic" (database) contents. The problem now is how to handle "static" contents for each different domain (eg. public/images folder on rails app is unique for all the domains and my goal is to handle static contents like images/javascripts/flash in different folders (one folder for each domain)). One possible solution is to handle a parameter for images and stylesheets eg. @domain.path but I think there is a better solution because in this case I must set the @domain.path parameter into each view... eg. <img src="<%= @domain.path%>/images/logo.gif"/> I would like to know if is there a better (dry) solution... Thanks in advance.> Gianluca, > Once you''ve learned to ''scope'' the @domain table based on the current > request.domain the rest is downhill. > If I had a table called ''content'' I''d use the before filter to find > the domain and then gather the collection like; > @content = @domain.contents.find(:all) and so on for any table in your > application. > Kathleen > > On Nov 6, 3:54 am, Gianluca Tessarolo > <tessarolo.gianl...-6ZZdBs7hMehZp5Udy/Obhg@public.gmane.org> wrote: > >> Thanks Kathy, Pablo and Greg, u r right. >> >> Your suggestions was very good and drive me into right direction, >> >> I solved the problem only setting 3 virtual hosts pointing to the same >> rails app and simply setting the base application controller filter (no >> routing map at all !): >> >> @domain = Domain.find_by_name(request.domain) >> >> Last question: >> >> How did u solve the different public folder for each domain ? >> >> In my application static contents must be separated for each different >> domainwww.first.com/www.second.com/www.third.comso I think I must >> have 3 different public folder, one for each different domain ? >> >> How can handle this into rails application ? (one possible solution is >> to handle a parameter for images and stylesheets ":path" but I think >> there is a better solution because in this case I have to use tha >> ":path" parameter into each view...). >> >> Thanks in advance... >> >> -- >> Gianluca Tessarolo >> TreNetMediaMaster S.r.l. >> The Internet Technology Company >> Telefono +39(049)776196 >> Fax +39(049)8087806 >> Visit us @:http://www.trenet.it-http://www.mediamaster.it >> e-mail me @: tessarolo.gianl...-6ZZdBs7hMehZp5Udy/Obhg@public.gmane.org >> ---------------------------------------------------------------------- >> Le informazioni trasmesse sono destinate esclusivamente alla persona o >> alla società in indirizzo e sono da intendersi confidenziali e riservate. >> Ogni trasmissione, inoltro, diffusione o altro uso di queste >> informazioni a persone o società differenti dal destinatario é proibita. >> Se ricevete questa comunicazione per errore, contattate il mittente e >> cancellate le informazioni da ogni computer. >> > > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---