Hello, I''m trying to figure out routes. Having some trouble getting my head around even how they are exposed to the rest of my application. For instance, if I set up my routes in routes.rb thusly: map.connect ''/:website_name/:controller/:action/:id'' I can for example refer to the following in my view: <%= link_to "login", :controller => "account", :action => "login" %> However, I don''t know how to set, or retrieve, my :website_name symbol in this example. I have been struggling a bit with this whole concept in general, so I''m going to try to help get better documentation going on if I can. It is really frustrating to me that the API docs at http://api.rubyonrails.com/classes/ActionController/ Routing.html simply refer to a Hieraki fragment that for some reason hasn''t answered any of my questions. Then again, maybe it''s just me. If everyone else understands the routing concept it might be that I''m just a bit slow, but I would love to ultimately see an example of an app that has both helpful custom routes and also a solid user authentication system, much like most real-world apps would work. But I digress. Any help in grokking the routes would be much appreciated. -raymond
Is not this what you want instead? map.connect ''/appname/:controller/:action/:id'' After this you can have your application based at: www.whatetever.com/appname/ By the way count me: I also found Routes documentation a bit shallow. Introductory tutorials are one thing API manuals another. Cheers, Zsombor On 5/2/05, Raymond Brigleb <ray-THGPwszTed5CpjqP0VxSwUEOCMrvLtNR@public.gmane.org> wrote:> Hello, I''m trying to figure out routes. Having some trouble getting > my head around even how they are exposed to the rest of my > application. For instance, if I set up my routes in routes.rb thusly: > > map.connect ''/:website_name/:controller/:action/:id'' > > I can for example refer to the following in my view: > > <%= link_to "login", :controller => "account", :action => "login" %> > > However, I don''t know how to set, or retrieve, my :website_name > symbol in this example. I have been struggling a bit with this whole > concept in general, so I''m going to try to help get better > documentation going on if I can. It is really frustrating to me that > the API docs at http://api.rubyonrails.com/classes/ActionController/ > Routing.html simply refer to a Hieraki fragment that for some reason > hasn''t answered any of my questions. > > Then again, maybe it''s just me. If everyone else understands the > routing concept it might be that I''m just a bit slow, but I would > love to ultimately see an example of an app that has both helpful > custom routes and also a solid user authentication system, much like > most real-world apps would work. But I digress. > > Any help in grokking the routes would be much appreciated. > > -raymond > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- http://deezsombor.blogspot.com
Dee, Thanks for the reply... still trying to figure the Route thing out, so maybe someone else will offer advice. This seems like a fairly common requirement...? On May 2, 2005, at 1:05 AM, Dee Zsombor wrote:> Is not this what you want instead? > map.connect ''/appname/:controller/:action/:id''That doesn''t seem to be one of my problems... my app is handling many websites, and so I need to get and set the :website_name "symbol" within my app, because each user may be managing many "websites."> By the way count me: I also found Routes documentation a bit shallow. > Introductory tutorials are one thing API manuals another.I posted something in the wiki about this, but it''s hard to tell if folks will stumble across it. Wikis can be hard to navigate sometimes like that. Now here''s a general, FWIW comment about the Wiki vs. Hieraki. I find Hieraki a bit frustrating. I like seeing docs in the wiki because I can comment on them, ask for clarification, and contribute. But once something sits in the Hieraki, it''s kinda frozen in time, and it loses most of the benefits that the wiki brings to the table. I should mention this in other threads, but I think the Hieraki is frustrating... in fact, for many of the articles posted in that system, the default "click to continue to the next page" links at the bottom don''t even work. It''s weird. I don''t think it''s a good system from a usability kinda standpoint. Just my two cents. -raymond
Raymond Brigleb wrote:> Dee, > > Thanks for the reply... still trying to figure the Route thing out, so > maybe someone else will offer advice. This seems like a fairly common > requirement...? > > On May 2, 2005, at 1:05 AM, Dee Zsombor wrote: > >> Is not this what you want instead? >> map.connect ''/appname/:controller/:action/:id'' > > > That doesn''t seem to be one of my problems... my app is handling many > websites, and so I need to get and set the :website_name "symbol" > within my app, because each user may be managing many "websites."This seems to be the same problem I''m working on. Given a base domain name example.com, I want to define routes such that foo.example.com and bar.example.com have different default controllers and actions. Similarly, bar.example.com/help and foo.example.com/help should map to different controllers and actions. The docs and examples I''ve seen for routes all focus on the path_info or script_name part of the URL. I''ve not been able to find anything that mentions routing based on the domain or subdomain (nor even a note saying if it can or cannot be done). I know that, once in a controller, the subdomain is available from the request object, and I''ve hacked up a routing controller to steer requests, but I get the feeling it is not the best approach. I''d rather just load the right controller in the first place. Does code inside of routes.rb have access to the domain at the time the mappings are defined or called? If so, how can one use the domain/subdomain values to define subdomain-specific routes? Thanks, James
All I''m trying to figure out at this point is how to set and retrieve the information in the current "route" (as shown in my URL) without resorting to manual regexp''s or stuff like that. I can set the :action and I can set the :controller, how do I set/retrieve my custom-built :website_name? Anyone know how to do this? -ray -- Raymond Brigleb, Needmore Designs Website http://needmoredesigns.com/ Email ray-THGPwszTed5CpjqP0VxSwUEOCMrvLtNR@public.gmane.org Phone 503.490.4595 On May 3, 2005, at 1:38 PM, James Britt wrote:> Raymond Brigleb wrote: > >> Dee, >> Thanks for the reply... still trying to figure the Route thing >> out, so maybe someone else will offer advice. This seems like a >> fairly common requirement...? >> On May 2, 2005, at 1:05 AM, Dee Zsombor wrote: >> >>> Is not this what you want instead? >>> map.connect ''/appname/:controller/:action/:id'' >>> >> That doesn''t seem to be one of my problems... my app is handling >> many websites, and so I need to get and set the :website_name >> "symbol" within my app, because each user may be managing many >> "websites." >> > > > This seems to be the same problem I''m working on. > > Given a base domain name example.com, I want to define routes such > that > > foo.example.com > > and > > bar.example.com > > have different default controllers and actions. > > Similarly, > > bar.example.com/help > > and > > foo.example.com/help > > should map to different controllers and actions. > > The docs and examples I''ve seen for routes all focus on the > path_info or script_name part of the URL. I''ve not been able to > find anything that mentions routing based on the domain or > subdomain (nor even a note saying if it can or cannot be done). > > I know that, once in a controller, the subdomain is available from > the request object, and I''ve hacked up a routing controller to > steer requests, but I get the feeling it is not the best approach. > I''d rather just load the right controller in the first place. > > Does code inside of routes.rb have access to the domain at the time > the mappings are defined or called? > > If so, how can one use the domain/subdomain values to define > subdomain-specific routes? > > > Thanks, > > > James > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Have you tried: <%= link_to "login", :controller => "account", :action => "login", :website_name => "name" %> (as suggested by the last example on http://manuals.rubyonrails.com/read/chapter/65 and careful reading of http://api.rubyonrails.com/classes/ActionView/Helpers/UrlHelper.html#M000330 suggests that is correct) Hadley On 5/3/05, Raymond Brigleb <ray-THGPwszTed5CpjqP0VxSwUEOCMrvLtNR@public.gmane.org> wrote:> All I''m trying to figure out at this point is how to set and retrieve > the information in the current "route" (as shown in my URL) without > resorting to manual regexp''s or stuff like that. I can set > the :action and I can set the :controller, how do I set/retrieve my > custom-built :website_name? > > Anyone know how to do this? > > -ray > -- > > Raymond Brigleb, Needmore Designs > Website http://needmoredesigns.com/ > Email ray-THGPwszTed5CpjqP0VxSwUEOCMrvLtNR@public.gmane.org > Phone 503.490.4595 > > > On May 3, 2005, at 1:38 PM, James Britt wrote: > > > Raymond Brigleb wrote: > > > >> Dee, > >> Thanks for the reply... still trying to figure the Route thing > >> out, so maybe someone else will offer advice. This seems like a > >> fairly common requirement...? > >> On May 2, 2005, at 1:05 AM, Dee Zsombor wrote: > >> > >>> Is not this what you want instead? > >>> map.connect ''/appname/:controller/:action/:id'' > >>> > >> That doesn''t seem to be one of my problems... my app is handling > >> many websites, and so I need to get and set the :website_name > >> "symbol" within my app, because each user may be managing many > >> "websites." > >> > > > > > > This seems to be the same problem I''m working on. > > > > Given a base domain name example.com, I want to define routes such > > that > > > > foo.example.com > > > > and > > > > bar.example.com > > > > have different default controllers and actions. > > > > Similarly, > > > > bar.example.com/help > > > > and > > > > foo.example.com/help > > > > should map to different controllers and actions. > > > > The docs and examples I''ve seen for routes all focus on the > > path_info or script_name part of the URL. I''ve not been able to > > find anything that mentions routing based on the domain or > > subdomain (nor even a note saying if it can or cannot be done). > > > > I know that, once in a controller, the subdomain is available from > > the request object, and I''ve hacked up a routing controller to > > steer requests, but I get the feeling it is not the best approach. > > I''d rather just load the right controller in the first place. > > > > Does code inside of routes.rb have access to the domain at the time > > the mappings are defined or called? > > > > If so, how can one use the domain/subdomain values to define > > subdomain-specific routes? > > > > > > Thanks, > > > > > > James > > > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
And to retrieve it, @params[:website_name] should work. -Chris On 5/3/05, hadley wickham <h.wickham-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Have you tried: > <%= link_to "login", :controller => "account", :action => "login", > :website_name => "name" %> > > (as suggested by the last example on > http://manuals.rubyonrails.com/read/chapter/65 and careful reading of > http://api.rubyonrails.com/classes/ActionView/Helpers/UrlHelper.html#M000330 > suggests that is correct) > > Hadley > > On 5/3/05, Raymond Brigleb <ray-THGPwszTed5CpjqP0VxSwUEOCMrvLtNR@public.gmane.org> wrote: > > All I''m trying to figure out at this point is how to set and retrieve > > the information in the current "route" (as shown in my URL) without > > resorting to manual regexp''s or stuff like that. I can set > > the :action and I can set the :controller, how do I set/retrieve my > > custom-built :website_name? > > > > Anyone know how to do this? > > > > -ray > > -- > > > > Raymond Brigleb, Needmore Designs > > Website http://needmoredesigns.com/ > > Email ray-THGPwszTed5CpjqP0VxSwUEOCMrvLtNR@public.gmane.org > > Phone 503.490.4595 > > > > > > On May 3, 2005, at 1:38 PM, James Britt wrote: > > > > > Raymond Brigleb wrote: > > > > > >> Dee, > > >> Thanks for the reply... still trying to figure the Route thing > > >> out, so maybe someone else will offer advice. This seems like a > > >> fairly common requirement...? > > >> On May 2, 2005, at 1:05 AM, Dee Zsombor wrote: > > >> > > >>> Is not this what you want instead? > > >>> map.connect ''/appname/:controller/:action/:id'' > > >>> > > >> That doesn''t seem to be one of my problems... my app is handling > > >> many websites, and so I need to get and set the :website_name > > >> "symbol" within my app, because each user may be managing many > > >> "websites." > > >> > > > > > > > > > This seems to be the same problem I''m working on. > > > > > > Given a base domain name example.com, I want to define routes such > > > that > > > > > > foo.example.com > > > > > > and > > > > > > bar.example.com > > > > > > have different default controllers and actions. > > > > > > Similarly, > > > > > > bar.example.com/help > > > > > > and > > > > > > foo.example.com/help > > > > > > should map to different controllers and actions. > > > > > > The docs and examples I''ve seen for routes all focus on the > > > path_info or script_name part of the URL. I''ve not been able to > > > find anything that mentions routing based on the domain or > > > subdomain (nor even a note saying if it can or cannot be done). > > > > > > I know that, once in a controller, the subdomain is available from > > > the request object, and I''ve hacked up a routing controller to > > > steer requests, but I get the feeling it is not the best approach. > > > I''d rather just load the right controller in the first place. > > > > > > Does code inside of routes.rb have access to the domain at the time > > > the mappings are defined or called? > > > > > > If so, how can one use the domain/subdomain values to define > > > subdomain-specific routes? > > > > > > > > > Thanks, > > > > > > > > > James > > > > > > _______________________________________________ > > > Rails mailing list > > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >