Ehud Rosenberg
2007-Apr-04 21:52 UTC
routing to the main www subdomain for specific controllers
Hi everyone! I''m using subdomains as user identifiers (username.localhost.com maps to the profile of that user). However, that complicates things as I do not want all controllers to work with those subdomains. Let''s say I have a user controller with a signup action. I do not want people to be able to go to anything.localhost.com/user/signup, and if they do I want them to be automatically redirected to www.localhost.com/user/signup. There would probably be lots of other controllers/actions I would like that to happen with. On the other hand, the blog controller index should only displayed when accesses from a subdomain (username.localhost.com/blog) but not from www.localhost.com/blog (that would redirect back to the main site). Question is how can i do this elegantly? Is there a way for me to automatically redirect to www.localhost.com in certain actions or do I have to check in the begining of each action if the subdomain is different the www and then redirect? Any help would be much appreacited! Ehud -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Peter De Berdt
2007-Apr-05 10:16 UTC
Re: routing to the main www subdomain for specific controllers
Check out http://agilewebdevelopment.com/plugins/request_routing On 04 Apr 2007, at 23:52, Ehud Rosenberg wrote:> I''m using subdomains as user identifiers (username.localhost.com > maps to > the profile of that user). However, that complicates things as I do > not > want all controllers to work with those subdomains. > > Let''s say I have a user controller with a signup action. I do not want > people to be able to go to anything.localhost.com/user/signup, and if > they do I want them to be automatically redirected to > www.localhost.com/user/signup. There would probably be lots of other > controllers/actions I would like that to happen with. > > On the other hand, the blog controller index should only displayed > when > accesses from a subdomain (username.localhost.com/blog) but not from > www.localhost.com/blog (that would redirect back to the main site). > > Question is how can i do this elegantly? Is there a way for me to > automatically redirect to www.localhost.com in certain actions or do I > have to check in the begining of each action if the subdomain is > different the www and then redirect? > > Any help would be much appreacited!Best regards Peter De Berdt --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Ehud Rosenberg
2007-Apr-05 11:05 UTC
Re: routing to the main www subdomain for specific controlle
Peter De Berdt wrote:> Check out http://agilewebdevelopment.com/plugins/request_routing > > On 04 Apr 2007, at 23:52, Ehud Rosenberg wrote: > >> controllers/actions I would like that to happen with. >> >> Any help would be much appreacited! > > > > Best regards > > Peter De BerdtHi Peter, I''m already using that plugin to allow routing based on subdomains. The problem is with redirection, not really routing (I think...). What i''m looking for is a way to redirect a call from subdomian.localhost.com/controller/action to www.localhost.com/controller/action - and do it in the simplest way possible. Ehud -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Xavier Noria
2007-Apr-05 11:22 UTC
Re: routing to the main www subdomain for specific controlle
On Apr 5, 2007, at 1:05 PM, Ehud Rosenberg wrote:> > Peter De Berdt wrote: >> Check out http://agilewebdevelopment.com/plugins/request_routing >> >> On 04 Apr 2007, at 23:52, Ehud Rosenberg wrote: >> >>> controllers/actions I would like that to happen with. >>> >>> Any help would be much appreacited! >> >> >> >> Best regards >> >> Peter De Berdt > > Hi Peter, > I''m already using that plugin to allow routing based on subdomains. > The problem is with redirection, not really routing (I think...). > > What i''m looking for is a way to redirect a call from > subdomian.localhost.com/controller/action to > www.localhost.com/controller/action - and do it in the simplest wayI have a high-priority filter in ApplicationController like this: # Prevents account sites from accessing to the public side. This filter # assumes the root page is not under public, which is to be expected, and # redirects there if needed. def check_access_to_public if controller_name == ''public'' && account_subdomain != ''www'' logger.info("attempt to access to a public action from an account site") redirect_to_url account_url(account_subdomain) return false end end It does not do what you want, but that filter depicts a possible approach. If your controllers do not mix public and private actions that filter may suffice. A set of controller names would be used instead of the hard-coded ''public'' (my app has all the public stuff served by a single controller). If there are too many as you suggested in a previous mail, then you could have abstract controllers AbstractPublicController, AbstractPrivateController between ApplicationController and the rest, and test is_a? (AbstractPublicController). The redirection would be different as well, but you see the idea. -- 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 -~----------~----~----~----~------~----~------~--~---