Roman Seidl
2004-Dec-13 15:49 UTC
Dispatcher? how to use long urls with slashes to call a controller
Hello rails, I have a controller called file with a method get that returns me a file from the db. want to do the following: When calling http://localhost:8080/file/get/11/hansi.txt i want that rails does the same as if i would call http://localhost:8080/file/get/11 This i not the case. I get a 404. This is useful as this makes the filename in the browser downloading the file be hansi.txt I use mod_ruby - an as far as i could see dispatcher.cgi ist called. And this calls the ruby\gems\1.8\gems\rails-0.8.5\lib\dispatcher.rb#self.dispatch. Is this true? Is dispatcher.cgi even called when i call http://localhost:8080/file/get/11/hansi.txt ? Anyone tried the same? Sorry but i really donŽt know the control flow between apache and rails. -- cheers, roman seidl mailto:rot-hxbVNg70ZfReoWH0uzbU5w@public.gmane.org
John Wilger
2004-Dec-13 16:35 UTC
Re: Dispatcher? how to use long urls with slashes to call a controller
On Mon, 13 Dec 2004 16:49:59 +0100, Roman Seidl <rot-hxbVNg70ZfReoWH0uzbU5w@public.gmane.org> wrote:> This is useful as this makes the filename in the browser downloading > the file be hansi.txtThis doesn''t directly answer your question, but you san always use the HTTP ''Content-Disposition'' header to control this. -- Regards, John Wilger ----------- Alice came to a fork in the road. "Which road do I take?" she asked. "Where do you want to go?" responded the Cheshire cat. "I don''t know," Alice answered. "Then," said the cat, "it doesn''t matter." - Lewis Carrol, Alice in Wonderland
Florian Weber
2004-Dec-13 17:45 UTC
Re: Dispatcher? how to use long urls with slashes to call a controller
On Dec 13, 2004, at 16:49 Uhr, Roman Seidl wrote:> Hello rails, > > I have a controller called file with a method get that returns me a > file from the db. > > want to do the following: > > When calling http://localhost:8080/file/get/11/hansi.txt i want that > rails does the same as if i would call > http://localhost:8080/file/get/11 > > This i not the case. I get a 404.how should rails handle the 11 and hansi.txt arguments? what should hansi.txt be passed as? the reason that it doesn''t recognize it as a action execution though, is this in the .htaccess RewriteRule ^([-_a-zA-Z0-9]+)/([-_a-zA-Z0-9]+)/([-_a-zA-Z0-9]+)/([0-9]+)$ /dispatch.cgi?module=$1&controller=$2&action=$3&id=$4 [QSA,L]
Stefan Arentz
2004-Dec-13 17:50 UTC
Re: Dispatcher? how to use long urls with slashes to call a controller
On Dec 13, 2004, at 4:49 PM, Roman Seidl wrote:> Hello rails, > > I have a controller called file with a method get that returns me a > file from the db. > > want to do the following: > > When calling http://localhost:8080/file/get/11/hansi.txt i want that > rails does the same as if i would call > http://localhost:8080/file/get/11 > > This i not the case. I get a 404.I''m not sure if there is a standard way to do that other than to add your own handler to webrick or do a mod_rewrite rule in apache. The latter could convert your request to something rails understands ''under the hood'' while the client still sees the original URL. What I really like in Spring (www.springframework.org) is that they have abstracted the url mapping. For example you can use a handler to have mappings like this: /**/*.html -> Controller1 /file/get/* -> Controller2 Or map Urls directly to bean names (named instances of a singleton controller). Or map a request the way ruby does, where part of the request URL is mapped to a method on a Controller. This way you are not tied in with what the framework gives you. And you can always add your own specialized handler mappings. (This does require some sort of IoC container / configuration file, which Rails seems to be trying to avoid at all cost :) S.
Roman Seidl
2004-Dec-14 23:07 UTC
Re[2]: Dispatcher? how to use long urls with slashes to call a controller
Hello Florian, FW> the reason that it doesn''t recognize it as a action execution though, FW> is this in the .htaccess FW> RewriteRule FW> ^([-_a-zA-Z0-9]+)/([-_a-zA-Z0-9]+)/([-_a-zA-Z0-9]+)/([0-9]+)$ FW> /dispatch.cgi?module=$1&controller=$2&action=$3&id=$4 [QSA,L] thanks for the proposal. I just added the following: RewriteRule ^download/([-_a-zA-Z0-9]+)/[-_a-z.A-Z0-9]*$ /file/get/$1 [QSA] [L] so i can use http://myhost/download/11/hansi.txt and now it works just fine -- cheers, Roman mailto:rot-hxbVNg70ZfReoWH0uzbU5w@public.gmane.org