Hi I have a RESTful controller that works when using a numeric ID. Now I would like to accept user login names as ID and for some of the cases this is an e-mail address. In short it boils down to routing the request URL GET /users/erik-O5WfVfzUwx8@public.gmane.org DELETE /users/erik-O5WfVfzUwx8@public.gmane.org to :controller => :users, :action => :show :controller => :users, :action => :delete And so on. Does anyone know how to do this. Grateful for any insight on this. /Erik --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
ESPNDev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Mar-18 22:48 UTC
Re: Make routes with e-mail address
There''s no reason why you couldn''t just pass those as the ids to the url helpers, but you need to update your controller user = User.find(params[:id]) to user = User.find_by_email(params[:id]) On Mar 18, 1:18 pm, Erik Lindblad <e...-gTO0lQh45js@public.gmane.org> wrote:> Hi > > I have a RESTful controller that works when using a numeric ID. Now I > would like to accept user login names as ID and for some of the cases > this is an e-mail address. In short it boils down to routing the > request URL > > GET /users/e...-O5WfVfzUwx8@public.gmane.org > DELETE /users/e...-O5WfVfzUwx8@public.gmane.org > > to > > :controller => :users, :action => :show > :controller => :users, :action => :delete > > And so on. Does anyone know how to do this. Grateful for any insight > on this. > > /Erik--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi and thanks for the input. The problem was that I wanted to use .xml as :format which was not possible without customized routes. I did some reading and came up with a solution which I post if anyone else has a similar problem: map.connect "customers/:login.:format", :controller => "customers", :action => "show", :conditions => {:method => :get}, :login => /\b[\w.%-]+@[\w.%-]+\.[a-zA-Z]{2,4}/ Kindest regards Erik On 18 Mar, 23:48, "ESPN...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <ESPN3.DL- Community...-xX8xgfAcNKEAvxtiuMwx3w@public.gmane.org> wrote:> There''s no reason why you couldn''t just pass those as the ids to the > url helpers, but you need to update your controller > > user = User.find(params[:id]) > to > user = User.find_by_email(params[:id]) > > On Mar 18, 1:18 pm, ErikLindblad<e...-gTO0lQh45js@public.gmane.org> wrote: > > > Hi > > > I have a RESTful controller that works when using a numeric ID. Now I > > would like to accept user login names as ID and for some of the cases > > this is an e-mail address. In short it boils down to routing the > > request URL > > > GET /users/e...-O5WfVfzUwx8@public.gmane.org > > DELETE /users/e...-O5WfVfzUwx8@public.gmane.org > > > to > > > :controller => :users, :action => :show > > :controller => :users, :action => :delete > > > And so on. Does anyone know how to do this. Grateful for any insight > > on this. > > > /Erik--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---