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!

On 28 August 2010 05:07, Ze Ca [email protected] wrote:

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 L. wrote:

On 28 August 2010 05:07, Ze Ca [email protected] wrote:

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

On Sat, Aug 28, 2010 at 5:14 AM, Ze Ca [email protected] 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,

Hassan S. ------------------------ [email protected]
twitter: @hassan

On Sat, Aug 28, 2010 at 7:30 AM, Ze Ca [email protected] wrote:

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:

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,

Hassan S. ------------------------ [email protected]
twitter: @hassan

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

Hassan S. wrote:

On Sat, Aug 28, 2010 at 7:30 AM, Ze Ca [email protected] wrote:

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:

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,

Hassan S. ------------------------ [email protected]
twitter: @hassan

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 S. wrote:

On Sat, Aug 28, 2010 at 5:14 AM, Ze Ca [email protected] 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,

Hassan S. ------------------------ [email protected]
twitter: @hassan

Hassan S. wrote:

On Sat, Aug 28, 2010 at 5:14 AM, Ze Ca [email protected] 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?

It’s more Twitter-friendly. See
http://groups.google.com/group/techvalleyrb/msg/ac3ce4ae6620268a?pli=1
for one possibility.

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

On Sat, Aug 28, 2010 at 9:21 AM, Marnen Laibow-Koser
[email protected] wrote:

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

It’s more Twitter-friendly.

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:


Hassan S. ------------------------ [email protected]
twitter: @hassan