Éric Malenfant wrote: > A probably noob-ish question about the restful urls, but I searched > the groups archives and could not find it. > > IIUC, "GET /users/bob" should return a page showing information about > the user identified with "bob", while "GET /users/new" returns a page > with a form for creating a new user. > > Ain't there an ambiguity there? Does that mean that I have to make > sure that no user chooses "new" as his id?
If you use such "permalinks" to identify the individual resources instead of their primary key id, then you'll need to make sure you add validation to make sure the resource URI is unique. "GET /users/new" is itself a resource identifier URI. It refers to the "New Form" resource. Similarly the "Edit Form" resource has the "GET /users/edit" identifier URI. Using the model's simple integer primary key in the resource URI eliminates this issue. I've seen some people combine the id with a textual identifier to produce URI's like "GET /users/1-bob" which would also solve this issue. "GET /users/2-new" would be distinct from "GET /users/new" so there would be no conflict. As a bonus the resource can still be easily queried by primary key by parsing "1-bob" into the integer 1, which matches the id for Bob's record. @user = User.find("1-bob".to_i) # User.find(1) -- 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-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.