how to make unique ids for URLs

The path I currently have for a record in the post table is this:

www.myrailsapp.com/post/id

here's the route:

map.resources :posts, :has_many => :comments

Any thoughts on how you would make the above this?

www.myrailsapp.com/1djs34 (or some join of randomly generated letters and numbers) so that users easily bookmark the page and access it later.

I'd want to replace the traditional path id with something more random. How would I make an extra column in the post table to do this?

Did some google searching, but I guess I'm not hitting the right keywords.

Thanks!

The path I currently have for a record in the post table is this:

www.myrailsapp.com/post/id

here's the route:

map.resources :posts, :has_many => :comments

Any thoughts on how you would make the above this?

www.myrailsapp.com/1djs34 (or some join of randomly generated letters and numbers) so that users easily bookmark the page and access it later.

Why cannot they bookmark page www.myrailsapp.com/post/631 just as easily as www.../1djs32?

Colin

I suppose they could, but I'd like to make the URL path as short as possible. Plus, it's a excuse to learn how it works :).

Colin Law wrote:

I suppose they could, but I'd like to make the URL path as short as possible.

Why? What possible value does an obfuscated and shortened URL offer anyone?

If anything, most users would get more value out of something like

  www.myrailsapp.com/post/631-what-were-they-thinking

which at least gives the user (as well as search engines!) *some* meta-information about the content of the resource...

Plus, it's a excuse to learn how it works :).

..and you could google `rails friendly urls` for implementation examples to study :slight_smile:

FWIW,

That is true... I guess what I'm trying to get at is avoid using the built in ids as the resource identifier... and instead just using a randomly generated number as the identifier:

www.myrailsapp.com/post/what-were-they-thinking-184952

Hassan Schroeder wrote:

Again, I don't know why you'd bother :slight_smile: but you could generate a separate number on creation and use that -- google 'rails UUID' for one approach.

HTH,

Awesome, thanks Hassan for pointing me in the right direction.

Hassan Schroeder wrote:

Hassan Schroeder wrote:

Point taken. But I'd still rather see a human/SEO-friendly URL in my browser and as appropriate provide a "tweetable" version on the page :slight_smile: