I''ve switched over to RESTful behavior on my site I am working on. A URL like this works fine: /make/1/model/2/year/1995 Assuming that make.find(1).name is ''Ford'' and model.find(2).name is ''Taurus'' (year is obvious) is it possible to be RESTful and still have pretty URLs? Such as: /vehicle/Ford/Taurus/1995 Of course this works in the old scheme with something like: map.vehicle vehicle/:make_name/:model_name/:year_id, :controller => ''vehicle'', :action => ''show'' 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-/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 -~----------~----~----~----~------~----~------~--~---
Part of the solution [the easy part] would be to implement to_param in your models to yield the product name/make rather than the id. I''m just not sure how to eliminate the words make, model, and year. Maybe someone else will respond to that. I''m a RESTful noob myself. RSL On 1/7/07, Carl Johnson <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > I''ve switched over to RESTful behavior on my site I am working on. > > A URL like this works fine: > > /make/1/model/2/year/1995 > > Assuming that make.find(1).name is ''Ford'' and model.find(2).name is > ''Taurus'' (year is obvious) is it possible to be RESTful and still have > pretty URLs? Such as: > > /vehicle/Ford/Taurus/1995 > > Of course this works in the old scheme with something like: > > map.vehicle vehicle/:make_name/:model_name/:year_id, :controller => > ''vehicle'', :action => ''show'' > > 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-/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 -~----------~----~----~----~------~----~------~--~---
I can live with the controller words in the URL if I have to. I was not aware of to_param. The docs don''t seem to really talk about to_param in this way and from reading a blog post or two it would seem to be "black magic". Not sure I want to go there... As far as I can tell the URL naming flexibility is just not available when RESTful, like it is with classic routing. That''s unfortunate. Russell Norris wrote:> Part of the solution [the easy part] would be to implement to_param in > your > models to yield the product name/make rather than the id. I''m just not > sure > how to eliminate the words make, model, and year. Maybe someone else > will > respond to that. I''m a RESTful noob myself. > > RSL-- 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 -~----------~----~----~----~------~----~------~--~---
If you want an idea on how to use to_param, check out the acts_as_sluggable. I believe the peepcode RESTful movie also goes over using to_param, but I could be incorrect. On 1/8/07, Carl Johnson <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > I can live with the controller words in the URL if I have to. > > I was not aware of to_param. The docs don''t seem to really talk about > to_param in this way and from reading a blog post or two it would seem > to be "black magic". Not sure I want to go there... > > As far as I can tell the URL naming flexibility is just not available > when RESTful, like it is with classic routing. That''s unfortunate. > > > Russell Norris wrote: > > Part of the solution [the easy part] would be to implement to_param in > > your > > models to yield the product name/make rather than the id. I''m just not > > sure > > how to eliminate the words make, model, and year. Maybe someone else > > will > > respond to that. I''m a RESTful noob myself. > > > > RSL > > > -- > 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 -~----------~----~----~----~------~----~------~--~---
On 1/8/07, Carl Johnson <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > I can live with the controller words in the URL if I have to. > > I was not aware of to_param. The docs don''t seem to really talk about > to_param in this way and from reading a blog post or two it would seem > to be "black magic". Not sure I want to go there... > > As far as I can tell the URL naming flexibility is just not available > when RESTful, like it is with classic routing. That''s unfortunate.Of course it is flexible. REST is about creating resources and making them usable with the HTTP verbs. That''s really all there is to it. Using map.resources doesn''t make your app RESTful, and not using map.resources doesn''t preclude you from making your app RESTful. It just automates a lot of the routing for you so it''s easier to get where you want to be. Pat --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> Of course it is flexible. REST is about creating resources and making > them usable with the HTTP verbs. That''s really all there is to it.Sorry, I should clarify. REST is flexible. I could create my own RESTful routes and links, of course. map.resources is not flexible in one area - it only accepts :id. As far as I can tell. -- 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 -~----------~----~----~----~------~----~------~--~---