I have a question about how URLs are created. This happens with the edit action on the controller. Instead of creating the URL as http://site.com/edit/1 it sticks the ID in the middle: http://site.com/1/edit Two questions: 1. What exactly is the reason behind this default? 2. How do I override it? I''ve tried searching but I''m not sure what terminology that I should search for: "default route/routing", "route edit", etc....didn''t turn up anything useful. ThanX in advance. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Mike Garey
2008-Mar-12 08:06 UTC
Re: Newbie Routing Question /site/1/edit vs. /site/edit/1
are you using restful routes? In any case, that''s quite strange.. The default should be :controller/:action/:id You''re also missing the controller name for some reason. is this a new rails application? Have you messed around with the routes file? Do all your urls for different controllers show up this same way? Are you using nested resources? On 3/12/08, Baz <bazil749-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have a question about how URLs are created. > > This happens with the edit action on the controller. > > Instead of creating the URL as http://site.com/edit/1 it sticks the ID in > the middle: > http://site.com/1/edit > > Two questions: > > 1. What exactly is the reason behind this default? > 2. How do I override it? > > I''ve tried searching but I''m not sure what terminology that I should search > for: "default route/routing", "route edit", etc....didn''t turn up anything > useful. > > > ThanX in advance. > > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Baz wrote:> Instead of creating the URL as http://site.com/edit/1 it sticks the ID > in > the middle: > http://site.com/1/editThis should be more like: http://site.com/controller/1/edit> 1. What exactly is the reason behind this default?These are RESTful routes. Google for "rails REST routes" or "rails 2 scaffolding" and you should get some useful info. Basically, it''s a way of treating your database objects as resources and performing actions on them. Many actions involve just the HTTP method (GET, POST, PUT, DELETE) (the verbs of the request) and either the controller name or the controller plus an object''s id field (the nouns of the request). The appended actions (like "edit" above) extend this "language". This means that the resource is: http://site.com/controller/1 and the action to be performed is encoded in the HTTP method (possibly augmented by an appended action to the resource). To see how this is put together, run the following command from your application''s top level directory: rake routes> 2. How do I override it?These resources are used when you have lines like this in your config/routes.rb file: map.resources :controller If you comment this out, you will see that there is a line later which reads: map.connect '':controller/:action/:id'' which will then provide you with the form of URLs you are looking for. Running the rake command again will show the difference. -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Right on the money Mark. ThanX. Yes, I was missing the site.com/controller/edit/1 ThanX I don''t take it there is a way to scaffold without these? eg. make it generate: link_to ''Show'', :action => ''show'', :id => controller ? On Wed, Mar 12, 2008 at 3:13 AM, Mark Bush <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Baz wrote: > > Instead of creating the URL as http://site.com/edit/1 it sticks the ID > > in > > the middle: > > http://site.com/1/edit > > This should be more like: > > http://site.com/controller/1/edit > > > 1. What exactly is the reason behind this default? > > These are RESTful routes. Google for "rails REST routes" or "rails 2 > scaffolding" and you should get some useful info. Basically, it''s a way > of treating your database objects as resources and performing actions on > them. Many actions involve just the HTTP method (GET, POST, PUT, > DELETE) (the verbs of the request) and either the controller name or the > controller plus an object''s id field (the nouns of the request). The > appended actions (like "edit" above) extend this "language". This means > that the resource is: > > http://site.com/controller/1 > > and the action to be performed is encoded in the HTTP method (possibly > augmented by an appended action to the resource). To see how this is > put together, run the following command from your application''s top > level directory: > > rake routes > > > 2. How do I override it? > > These resources are used when you have lines like this in your > config/routes.rb file: > > map.resources :controller > > If you comment this out, you will see that there is a line later which > reads: > > map.connect '':controller/:action/:id'' > > which will then provide you with the form of URLs you are looking for. > Running the rake command again will show the difference. > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---