I would appreciate it if someone could post a clear, understandable description of how URLs are handled by Rails. There is currently scattered documentation, but nothing I''ve found that quite ties it altogether. It would be great if there could be an overview document that would answer the following questions (and, in the meantime, if someone could clarify this in this forum, that''d be great, too): 1. I understand that url remapping is handled by .htaccess files. So how is it that webrick seems to do at least some url remapping? That is, with webrick I can use either of these urls: http://localhost:3000/customer?action=display&id=1 http://localhost:3000/customer/display/1 and the same page is displayed. But (as far as I know), .htaccess is not being used. 2. In the documentation for ActionPack::url_for, a URL is defined this way: <controller_prefix>/<controller>/<action_prefix>/<action> Now I''m confused again. What''s this "controller_prefix"? It''s not mentioned in the examples, which tend to be of the form: <controller>/<action> OR <controller>/<action>/<id> OR <controller>/<action>/<action_prefix>/<action> It''s not clear to me that webrick, for one, can successfully map URLs like the last one. I''m totally unclear whether there is a canonical way that URLs are suggested to be mapped, or whether this is supposed to be something that only works correctly if you set up .htaccess and use apache. (When I tried to create a URL with an <action_prefix>, rails evidently assumed that I had specified a <controller_prefix>). 3. If a URL is received in this form: <controller_prefix>/<controller>/<action_prefix>/<action>/<id> what is the convention that decides which part of the URL to map to the pieces above? Especially since some pieces (e.g. action_prefix) may be more than one path component? 4. Finally, what are the rules for how these are actually mapped to controller components? That is, what code is actually invoked? Thanks, Bob
On Wed, Dec 22, 2004 at 06:01:00PM -0800, Bob Sidebotham wrote:> I would appreciate it if someone could post a clear, understandable > description of how URLs are handled by Rails. There is currently > scattered documentation, but nothing I''ve found that quite ties it > altogether. It would be great if there could be an overview document > that would answer the following questions (and, in the meantime, if > someone could clarify this in this forum, that''d be great, too): > > 1. I understand that url remapping is handled by .htaccess files. So > how is it that webrick seems to do at least some url remapping? That > is, with webrick I can use either of these urls: > > http://localhost:3000/customer?action=display&id=1this is the real url> http://localhost:3000/customer/display/1this is the visible url. The RewriteRules in .htaccess converts this url to the real url.> > and the same page is displayed. But (as far as I know), .htaccess is > not being used. > > 2. In the documentation for ActionPack::url_for, a URL is defined this way: > > <controller_prefix>/<controller>/<action_prefix>/<action> > > Now I''m confused again. What''s this "controller_prefix"? It''s not > mentioned in the examples, which tend to be of the form: > > <controller>/<action> > OR > <controller>/<action>/<id> > OR > <controller>/<action>/<action_prefix>/<action> > > It''s not clear to me that webrick, for one, can successfully map URLs > like the last one. I''m totally unclear whether there is a canonical > way that URLs are suggested to be mapped, or whether this is supposed > to be something that only works correctly if you set up .htaccess and > use apache. (When I tried to create a URL with an <action_prefix>, > rails evidently assumed that I had specified a <controller_prefix>). > > 3. If a URL is received in this form: > > <controller_prefix>/<controller>/<action_prefix>/<action>/<id> > > what is the convention that decides which part of the URL to map to > the pieces above? Especially since some pieces (e.g. action_prefix) > may be more than one path component? > > 4. Finally, what are the rules for how these are actually mapped to > controller components? That is, what code is actually invoked? >You can see the rules in .htaccess -- Roeland
On Thu, 23 Dec 2004 13:12:42 +0100, Roeland Moors <roelandmoors-CNXmb7IdZIWZIoH1IeqzKA@public.gmane.org> wrote:> The RewriteRules in .htaccess converts this url to the real url.My question (one of them, anyway) was: how does this work in _Webrick_? Because it''s obvious to me that some sort of remapping is happening even with webrick rather than apache. I am pretty sure that webrick does not support .htaccess--because .htaccess files are essentially apache configuration files. There is no mention of this in the webrick documentation, nor would I expect there to be (webrick is supposed to relatively simple, after all). Someone must have the answer to these questions (David?). Thanks, Bob P.S. I suppose I could role up my sleeves and actually look at the code--but I was just hoping for quick answer...
> My question (one of them, anyway) was: how does this work in > _Webrick_? Because it''s obvious to me that some sort of remapping is > happening even with webrick rather than apache.Currently, the URL scheme in WEBrick is rather fixed. That''s changing rapidly, though. Ulysses has just released the first preview of his patch to make this happen. It''s available on http://dev.rubyonrails.org/trac.cgi/ticket/368. -- David Heinemeier Hansson, http://www.basecamphq.com/ -- Web-based Project Management http://www.rubyonrails.org/ -- Web-application framework for Ruby http://macromates.com/ -- TextMate: Code and markup editor (OS X) http://www.loudthinking.com/ -- Broadcasting Brain
Answering your question, the remapping happens in: File: ruby\lib\ruby\gems\1.8\gems\rails-0.9.2\lib\webrick_server.rb Class/method: DispatchServlet#self.parse_uri I had to tweak this a little bit for my app, and I did this redefining the parse_uri method in my own app, so no need to modify the original Rails source code. (I love Ruby for open classes!) Rgds David Heinemeier Hansson wrote:>> My question (one of them, anyway) was: how does this work in >> _Webrick_? Because it''s obvious to me that some sort of remapping is >> happening even with webrick rather than apache. > > > Currently, the URL scheme in WEBrick is rather fixed. That''s changing > rapidly, though. Ulysses has just released the first preview of his > patch to make this happen. It''s available on > http://dev.rubyonrails.org/trac.cgi/ticket/368. > -- > David Heinemeier Hansson, > http://www.basecamphq.com/ -- Web-based Project Management > http://www.rubyonrails.org/ -- Web-application framework for Ruby > http://macromates.com/ -- TextMate: Code and markup editor (OS X) > http://www.loudthinking.com/ -- Broadcasting Brain > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > >