hi guys, sorry to trouble you all but i really dont understand how this routing thing work... it seems easy but it just dont work for me! here''s the situation : my url b4 : http://127.0.0.1:3001/admin/login my url after: http://127.0.0.1:3001/burninglegion/admin/login i wanna do something like this so i went to the routes.rb and type this: ActionController::Routing::Routes.draw do |map| map.connect "burninglegion/:controller/:action/:id" #i typed this map.connect '':controller/service.wsdl'', :action => ''wsdl'' #default map.connect '':controller/:action/:id'' end ok when i typed the initial url http://127.0.0.1:3001/burninglegion/admin/login, it would display the page but when it logged in, it changed to http://127.0.0.1:3001/admin/main which missed the constant name.... is wat i do correct??? some i got like 3 controllers and i hope that it would apply to everyone of them...is that possible??? thanks thanks -- Posted via http://www.ruby-forum.com/.
In your case, you could do the following: map.connect "burninglegion/admin/login", :controller => "some_controller", :action => "some_action" If you want more explanation, take the below url and the defined route. http://mysite.com:3000/all/eudora/7.0.1/windows/download/5 map.download '':platform_filter/:software/:version/:platform/:distribution_channel/:id'', :controller => ''user/version'', :platform_filter => /all/, :platform => /windows/linux/, :distribution_channel => /download/, :action => ''download'', :id => /\d+/ Here''s how--I think--the match is determined: 1. Rails looks at the first portion of the url--"all"--and checks to see if it will be accepted by my route as :platform_filter. It matches my regex constraint for :platform_filter, so platform_filter => "all" is set. 2. Rails inspects the next url item--"eudora"--checks to see if it matches my mapping constraint. There is no constraint, so it matches, sets :software => "eudora". 3. Rails inspects the next url item--"7.0.1"--checks to see if it matches my mapping constraint. There is no constraint, so :version => "7.0.1" is set. 4. Rails inspects the next url item--"windows"--checks to see if it matches my mapping constraint. It matches my regex constraint, so platform => "windows" is set. 5. Rails inspects the next url item--"download"--checks to see if it matches my mapping constraint. It matches my regex constraint, so :distribution_channel => "download" is set. 6. Rails inspects the last url item--"5"--checks to see if it matches my mapping constraint. It matches my regex constraint, so :id => "download" is set. 7. All the url portions mapped, so this route will be used. 8. Rails looks at the :controller and the :action defined in this route and executes them, passing all the matchig url portions via the params hash. Ex: we can access the :software portion of the url like this--params[:software] If any of the above steps do not match, the route is skipped, the keys are cleared and the process is repeated with the next route. I hope this helps, Steven bao lee wrote:> hi guys, sorry to trouble you all but i really dont understand how this > routing thing work... it seems easy but it just dont work for me! > > here''s the situation : > > my url b4 : http://127.0.0.1:3001/admin/login > my url after: http://127.0.0.1:3001/burninglegion/admin/login > > i wanna do something like this so i went to the routes.rb and type this: > > ActionController::Routing::Routes.draw do |map| > > map.connect "burninglegion/:controller/:action/:id" #i typed this > map.connect '':controller/service.wsdl'', :action => ''wsdl'' > #default > map.connect '':controller/:action/:id'' > end > > ok when i typed the initial url > http://127.0.0.1:3001/burninglegion/admin/login, it would display the > page but when it logged in, it changed to > > http://127.0.0.1:3001/admin/main > > which missed the constant name.... is wat i do correct??? > > some i got like 3 controllers and i hope that it would apply to everyone > of them...is that possible??? > > thanks thanks > >
On 6/8/06, Steven Hansen <runner@berkeley.edu> wrote:> > In your case, you could do the following: > > map.connect "burninglegion/admin/login", > :controller => "some_controller", > :action => "some_action" > > > > If you want more explanation, take the below url and the defined route. > > http://mysite.com:3000/all/eudora/7.0.1/windows/download/5 > > map.download > '':platform_filter/:software/:version/:platform/:distribution_channel/:id'', > :controller => ''user/version'', > :platform_filter => /all/, > :platform => /windows/linux/, > :distribution_channel => /download/, > :action => ''download'', > :id => /\d+/ > > > Here''s how--I think--the match is determined: > > 1. Rails looks at the first portion of the url--"all"--and checks to > see if it will be accepted by my route as :platform_filter. It > matches my regex constraint for :platform_filter, so > platform_filter => "all" is set. > 2. Rails inspects the next url item--"eudora"--checks to see if it > matches my mapping constraint. There is no constraint, so it > matches, sets :software => "eudora". > 3. Rails inspects the next url item--"7.0.1"--checks to see if it > matches my mapping constraint. There is no constraint, so :version > => "7.0.1" is set. > 4. Rails inspects the next url item--"windows"--checks to see if it > matches my mapping constraint. It matches my regex constraint, so > platform => "windows" is set. > 5. Rails inspects the next url item--"download"--checks to see if it > matches my mapping constraint. It matches my regex constraint, so > :distribution_channel => "download" is set. > 6. Rails inspects the last url item--"5"--checks to see if it matches > my mapping constraint. It matches my regex constraint, so :id => > "download" is set. > 7. All the url portions mapped, so this route will be used. > 8. Rails looks at the :controller and the :action defined in this > route and executes them, passing all the matchig url portions via > the params hash. Ex: we can access the :software portion of the > url like this--params[:software] > > If any of the above steps do not match, the route is skipped, the keys > are cleared and the process is repeated with the next route. > > > I hope this helps, > Steven > > > bao lee wrote: > > > > > hi guys, sorry to trouble you all but i really dont understand how this > > routing thing work... it seems easy but it just dont work for me! > > > > here''s the situation : > > > > my url b4 : http://127.0.0.1:3001/admin/login > > my url after: http://127.0.0.1:3001/burninglegion/admin/login > > > > i wanna do something like this so i went to the routes.rb and type this: > > > > ActionController::Routing::Routes.draw do |map| > > > > map.connect "burninglegion/:controller/:action/:id" #i typed this > > map.connect '':controller/service.wsdl'', :action => ''wsdl'' > > #default > > map.connect '':controller/:action/:id'' > > end > > > > ok when i typed the initial url > > http://127.0.0.1:3001/burninglegion/admin/login, it would display the > > page but when it logged in, it changed to > > > > http://127.0.0.1:3001/admin/main > > > > which missed the constant name.... is wat i do correct??? > > > > some i got like 3 controllers and i hope that it would apply to everyone > > of them...is that possible??? > > > > thanks thanks > > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >Excellent explanation. Kudos, Steve. -- -Alder
Alder Green wrote:> On 6/8/06, Steven Hansen <runner@berkeley.edu> wrote: >> >> >> 3. Rails inspects the next url item--"7.0.1"--checks to see if it >> "download" is set. >> I hope this helps, >> > here''s the situation : >> > #default >> > >> > Excellent explanation. Kudos, Steve.so do you mean i have to explicitly define all the routes? ok in admin i have the following actions like login, logout, main, search and add_user so i have to explicitly state all of them? like this? map.connect "burninglegion/admin/login", :controller => "admin", :action => "login" map.connect "burninglegion/admin/logout", :controller => "admin", :action => "logout" map.connect "burninglegion/admin/search", :controller => "admin", :action => "search" map.connect "burninglegion/admin/add_user", :controller => "admin", :action => "add_user" map.connect "burninglegion/admin/main", :controller => "admin", :action => "main" omg.... is there a more dynamic way??? cos i just wanna add my name in front of all the url only T-T -- Posted via http://www.ruby-forum.com/.
bao lee wrote:> > so do you mean i have to explicitly define all the routes? > ok in admin i have the following actions like login, logout, main, > search and add_user so i have to explicitly state all of them? like > this? > > map.connect "burninglegion/admin/login", > :controller => "admin", > :action => "login" > > map.connect "burninglegion/admin/logout", > :controller => "admin", > :action => "logout" > > map.connect "burninglegion/admin/search", > :controller => "admin", > :action => "search" > > map.connect "burninglegion/admin/add_user", > :controller => "admin", > :action => "add_user" > > map.connect "burninglegion/admin/main", > :controller => "admin", > :action => "main" > > omg.... is there a more dynamic way??? cos i just wanna add my name in > front of all the url only T-Twould this work? map.connect "burninglegion/admin/:action", :controller => ''admin'' -- Posted via http://www.ruby-forum.com/.
Ken Kam wrote:> would this work? > > map.connect "burninglegion/admin/:action", > :controller => ''admin'':D yeah.... this worked for the admin controller only...ahaha so i just duplicate it for other controllers like map.connect "burninglegion/admin/:action", :controller => ''admin'' map.connect "burninglegion/blog/:action", :controller => ''blog'' map.connect "burninglegion/test/:action", :controller => ''test'' the controller name have to be explicit so that RoR will know which controller you are referring to.. although it seems abit un dynamic but that;s the best i could do!... thanks everyone for help! especially steven and ken -- Posted via http://www.ruby-forum.com/.
bao lee wrote:> Ken Kam wrote: >> would this work? >> >> map.connect "burninglegion/admin/:action", >> :controller => ''admin'' > > :D yeah.... this worked for the admin controller only...ahaha > > so i just duplicate it for other controllers like > > map.connect "burninglegion/admin/:action", :controller => ''admin'' > map.connect "burninglegion/blog/:action", :controller => ''blog'' > map.connect "burninglegion/test/:action", :controller => ''test'' > > the controller name have to be explicit so that RoR will know which > controller you are referring to.. > > although it seems abit un dynamic but that;s the best i could do!... > thanks everyone for help! especially steven and kenSorry, I forgot to tell you that you had to do that for every controller. However, have you tried doing this? map.connect "burninglegion/:controller/:action/:id" Now, I am completely unsure whether this would work, but worth a try. I also forgot to tell you to add :id. That routes anything after the action and passes it to your application as a params hash. Hence, /burninglegion/admin/show/38 would mean that params[:id] == 38. -- Posted via http://www.ruby-forum.com/.
Ken Kam wrote:> bao lee wrote: >> Ken Kam wrote: >>> would this work? >>> >>> map.connect "burninglegion/admin/:action", >>> :controller => ''admin'' >> >> :D yeah.... this worked for the admin controller only...ahaha >> >> so i just duplicate it for other controllers like >> >> map.connect "burninglegion/admin/:action", :controller => ''admin'' >> map.connect "burninglegion/blog/:action", :controller => ''blog'' >> map.connect "burninglegion/test/:action", :controller => ''test'' >> >> the controller name have to be explicit so that RoR will know which >> controller you are referring to.. >> >> although it seems abit un dynamic but that;s the best i could do!... >> thanks everyone for help! especially steven and ken > > Sorry, I forgot to tell you that you had to do that for every > controller. > > However, have you tried doing this? > > map.connect "burninglegion/:controller/:action/:id" > > Now, I am completely unsure whether this would work, but worth a try. > > I also forgot to tell you to add :id. That routes anything after the > action and passes it to your application as a params hash. Hence, > /burninglegion/admin/show/38 would mean that params[:id] == 38.i tried that in the beginning and it would only work for the first page .eg. the one you typed in... after that it wouldn''t work for the subsequent page... i dunno whether is my coding problem or wat.... -- Posted via http://www.ruby-forum.com/.
It looks like you might want to redefine the relative URL root, with something like this: ActionController::AbstractRequest.relative_url_root = "/burninglegion" I use this (in association with appropriate code in lighttpd.conf) to run two rails apps on the same domain, using the first part of the URL after the domain to distinguish between them (test.com/app1/user/login vs. test.com/app2/user/login). Asa -- Posted via http://www.ruby-forum.com/.