Yeah... I''m totally struggling to grok resource routes too... seems like they''ve totally blown the beautiful simplicity of the old url pattern stuff out of the water. Would love to hear an answer to this question!!! b Andy Triboletti wrote: > I want to customize map.resources so it uses a uid in the URL instead > of the database id. The uid is a field on my object. > > So I have map.resources :things in routes.rb and I can update a thing > by accessing POST /thing/1. Instead I want to update the thing by > POST /thing/80ed14ce098affc2 The thing has an id of 1 and a uid of > 80ed14ce098affc2 > > Any options other then getting rid of map.resources and explicitly > defining all the REST routes? > > Thanks > Andy > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Found a solution and that is to override to_param on each of the objects, so in the thing model I have def to_param "#{uid}" end Then in things_controller I have def show @thing = Thing.find_by_uid(params[:id]) end There''s also a patch out at http://dev.rubyonrails.org/ticket/6814, which allows you to use map.resources :things, :key => :uid and that way you could just use Thing.find(:params:uid) in your controller. Andy On Feb 9, 2007, at 1:39 PM, Ben Munat wrote:> > Yeah... I''m totally struggling to grok resource routes too... seems > like > they''ve totally blown the beautiful simplicity of the old url pattern > stuff out of the water. > > Would love to hear an answer to this question!!! > > b > > Andy Triboletti wrote: >> I want to customize map.resources so it uses a uid in the URL instead >> of the database id. The uid is a field on my object. >> >> So I have map.resources :things in routes.rb and I can update a thing >> by accessing POST /thing/1. Instead I want to update the thing by >> POST /thing/80ed14ce098affc2 The thing has an id of 1 and a uid of >> 80ed14ce098affc2 >> >> Any options other then getting rid of map.resources and explicitly >> defining all the REST routes? >> >> Thanks >> Andy >> > >--~--~---------~--~----~------------~-------~--~----~ 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 2/9/07, Andy Triboletti <andy-kRVt9sEkMUDQT0dZR+AlfA@public.gmane.org> wrote:> > Found a solution and that is to override to_param on each of the > objects, so in the thing model I have > > def to_param > "#{uid}" > end > > Then in things_controller I have > > def show > @thing = Thing.find_by_uid(params[:id]) > end > > There''s also a patch out at http://dev.rubyonrails.org/ticket/6814, > which allows you to use map.resources :things, :key => :uid and that > way you could just use > > Thing.find(:params:uid) > > in your controller. > > AndyJust to make it clear, there''s nothing in the resource routes that prevent you from using an alternate field. It all has to do with what your controllers expect to find in the params[:id] parameter. -- Rick Olson 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 -~----------~----~----~----~------~----~------~--~---