jf.cron0-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Jun-04 21:25 UTC
Custom URL/path for map.resources ?
Hi, what should I do if I want to customize/get rid of the controller name that''s part of the URL generated by default by map.resources ? What I mean is I would like : /posts/5 to become: /5 or: /blah/5 That must be a really easy thing to do, however I cannot figure out even by checking the API. Thanks! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
jf.cron0-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Jun-04 21:32 UTC
Re: Custom URL/path for map.resources ?
Ok, I''ve found how to do it the non-RESTful way by adding this to my routes.rb map.connect '':id'', :controller => "posts", :action => ''show'' However, I''m wondering if there is a better way of doing it when using a RESTful design? Thanks On 4 juin, 17:25, "jf.cr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <jf.cr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > what should I do if I want to customize/get rid of the controller name > that''s part of the URL generated by default by map.resources ? > > What I mean is I would like : /posts/5 > to become: /5 > or: /blah/5 > > That must be a really easy thing to do, however I cannot figure out > even by checking the API. > > Thanks!--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
What?? I must assume that your application has only one single resource, and will never have any more than that? I don''t see how this could be done in a truly RESTful way given that a major part of the REST URL is to identify the "resource" that you want to access. In your case that would be the Post resource (i.e. posts collection). Otherwise what meaning would /5 have? The 5th item in a collection of what? Another option would be to use a named route, but that isn''t really RESTful either. P.S. The "posts" in the URL is not really the controller name. It is the resource name/identifier. Read "GET: /posts/5" as GET the 5th item from the posts collection of Post resources. On Jun 4, 5:32 pm, "jf.cr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <jf.cr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Ok, I''ve found how to do it the non-RESTful way by adding this to my > routes.rb > > map.connect '':id'', :controller => "posts", :action => ''show'' > > However, I''m wondering if there is a better way of doing it when using > a RESTful design? > > Thanks > > On 4 juin, 17:25, "jf.cr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <jf.cr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hi, > > > what should I do if I want to customize/get rid of the controller name > > that''s part of the URL generated by default by map.resources ? > > > What I mean is I would like : /posts/5 > > to become: /5 > > or: /blah/5 > > > That must be a really easy thing to do, however I cannot figure out > > even by checking the API. > > > Thanks!--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 6/4/07, jf.cron0-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <jf.cron0-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi, > > what should I do if I want to customize/get rid of the controller name > that''s part of the URL generated by default by map.resources ? > > What I mean is I would like : /posts/5 > to become: /5 > or: /blah/5 > > That must be a really easy thing to do, however I cannot figure out > even by checking the API.Just use map.connect. Consider map.resources your reward for following conventions. In this case you''re not, so you''ll have to use map.connect. Also, just because you''re not following standard rails restful conventions doesn''t mean it''s not a REST service. map.resources sets up routes in a specific style, that''s all. -- Rick Olson http://lighthouseapp.com http://weblog.techno-weenie.net http://mephistoblog.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 -~----------~----~----~----~------~----~------~--~---
jf.cron0-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Jun-05 01:46 UTC
Re: Custom URL/path for map.resources ?
Thanks for the input. That makes sence and I must admit that I didn''t think about what I was doing :-) On 4 juin, 19:25, Robert Walker <rwalker...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> What?? > > I must assume that your application has only one single resource, and > will never have any more than that? I don''t see how this could be > done in a truly RESTful way given that a major part of the REST URL is > to identify the "resource" that you want to access. In your case that > would be the Post resource (i.e. posts collection). Otherwise what > meaning would /5 have? The 5th item in a collection of what? > > Another option would be to use a named route, but that isn''t really > RESTful either. > > P.S. The "posts" in the URL is not really the controller name. It is > the resource name/identifier. Read "GET: /posts/5" as GET the 5th > item from the posts collection of Post resources. > > On Jun 4, 5:32 pm, "jf.cr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <jf.cr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Ok, I''ve found how to do it the non-RESTful way by adding this to my > > routes.rb > > > map.connect '':id'', :controller => "posts", :action => ''show'' > > > However, I''m wondering if there is a better way of doing it when using > > a RESTful design? > > > Thanks > > > On 4 juin, 17:25, "jf.cr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <jf.cr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Hi, > > > > what should I do if I want to customize/get rid of the controller name > > > that''s part of the URL generated by default by map.resources ? > > > > What I mean is I would like : /posts/5 > > > to become: /5 > > > or: /blah/5 > > > > That must be a really easy thing to do, however I cannot figure out > > > even by checking the API. > > > > Thanks!--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---