In the "Head First Rails" book, it mentions this ordering in routes.rb: ActionController: : Routing: : Routes. draw do | map| map. connect '' /ads/new'' , : controller=>'' ads'' , : action=>'' new'' map. connect '' /ads/create'' , : controller=>'' ads'' , : action=>'' create'' map. connect '' /ads/'' , : controller=>'' ads'' , : action=>'' index'' map. connect '' /ads/: id'' , : controller=>'' ads'' , : action=>'' show'' If we enter: map. connect '' /ads/: id'' , : controller=>'' ads'' , : action=>'' show'' At the top of the ordering, how will that affect our routing. Can you just describe how to order routes in routes.rb? I mean, what is the rule to follow when ordering routes? Thanks. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 20 August 2010 13:23, Abder-Rahman Ali <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> In the "Head First Rails" book, it mentions this ordering in routes.rb: > > ActionController: : Routing: : Routes. draw do | map| > map. connect '' /ads/new'' , : controller=>'' ads'' , : action=>'' new'' > map. connect '' /ads/create'' , : controller=>'' ads'' , : action=>'' > create'' > map. connect '' /ads/'' , : controller=>'' ads'' , : action=>'' index'' > map. connect '' /ads/: id'' , : controller=>'' ads'' , : action=>'' show'' > > If we enter: > > map. connect '' /ads/: id'' , : controller=>'' ads'' , : action=>'' show'' > > At the top of the ordering, how will that affect our routing. > > Can you just describe how to order routes in routes.rb? I mean, what is > the rule to follow when ordering routes?The first entry in the file that matches is used, later ones are disregarded, so if you put the /ads/:id one at the start (note there is no space after the colon), then if a url matches that route then later ones will not be tested. You can always try it and see for yourself what happens. Have a look at the Rails Guide on routing for more information. Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Abder-Rahman Ali wrote:> In the "Head First Rails" book, it mentions this ordering in routes.rb: > > ActionController: : Routing: : Routes. draw do | map| > map. connect '' /ads/new'' , : controller=>'' ads'' , : action=>'' new'' > map. connect '' /ads/create'' , : controller=>'' ads'' , : action=>'' > create'' > map. connect '' /ads/'' , : controller=>'' ads'' , : action=>'' index'' > map. connect '' /ads/: id'' , : controller=>'' ads'' , : action=>'' show'' > > If we enter: > > map. connect '' /ads/: id'' , : controller=>'' ads'' , : action=>'' show'' > > At the top of the ordering, how will that affect our routing. > > Can you just describe how to order routes in routes.rb? I mean, what is > the rule to follow when ordering routes? > > Thanks.I''m not sure how old "Head First Rails" is, though I''m thinking 2008. If you''re getting started take a look at Ruby on Rails Guides (as Colin mentioned), which has an excellent page for this topic: http://guides.rubyonrails.org/routing.html Using RESTful routes simplifies that that example is trying to achieve by a lot, and using them I rarely run into the precedence issue: map.resources :ads, :only => [:index, :new, :create, :show] -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Abder-Rahman Ali wrote:> In the "Head First Rails" book, it mentions this ordering in routes.rb: > > ActionController: : Routing: : Routes. draw do | map| > map. connect '' /ads/new'' , : controller=>'' ads'' , : action=>'' new'' > map. connect '' /ads/create'' , : controller=>'' ads'' , : action=>'' > create'' > map. connect '' /ads/'' , : controller=>'' ads'' , : action=>'' index'' > map. connect '' /ads/: id'' , : controller=>'' ads'' , : action=>'' show'' > > If we enter: > > map. connect '' /ads/: id'' , : controller=>'' ads'' , : action=>'' show'' > > At the top of the ordering, how will that affect our routing. > > Can you just describe how to order routes in routes.rb? I mean, what is > the rule to follow when ordering routes?The first matched route rules. If you read any Rails routing reference, you''ll find that is says just this. Once again, the bigger answer: spend less time posting and more time reading. Virtually every question you''ve asked on this list could have been answered by 30 seconds with Google and/or 5 minutes with documentation.> > Thanks.Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks everyone. Yes, Parker, the "Head First Rails" is 2008. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.