I have a simple blog app that lets me create an entry with title and a body... real simple. In addition to the id that the database creates by default per each entry I would love to associate an unique id that uses 0123456789 and the 26 letters of the English alphabet. So that means I have 36^7 unique ids right? assuming I want to keep each unique combination no bigger than 7 digits, Why? This is hypothetical. Can anyone help point me into the right direction? the intended result would be 00001, 00002, 00003 etc etc. I was thinking to using a foor loop but a friend said that was a bad idea. A newbie here, I guess i dont have to point that out, anyone that can help me will be great. Thanks Oliver. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Quoting oliver torres <senortowers-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> I have a simple blog app that lets me create an entry with title and a > body... real simple. > In addition to the id that the database creates by default per each > entry I would love to associate an unique id that uses > 0123456789 and the 26 letters of the English alphabet. > > So that means I have 36^7 unique ids right? assuming I want to keep > each unique combination no bigger than 7 digits, Why? This is > hypothetical. > Can anyone help point me into the right direction? > the intended result would be 00001, 00002, 00003 etc etc. > > I was thinking to using a foor loop but a friend said that was a bad > idea. > A newbie here, I guess i dont have to point that out, anyone that can > help me will be great. > Thanksirb(main):006:0> 50.to_s(36) => "1e" 50 base 36 = 1*36 + 14 HTH, Jeffrey -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Jeffrey L. Taylor wrote:> Quoting oliver torres <senortowers-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: >> the intended result would be 00001, 00002, 00003 etc etc. >> >> I was thinking to using a foor loop but a friend said that was a bad >> idea. >> A newbie here, I guess i dont have to point that out, anyone that can >> help me will be great. >> Thanks > > irb(main):006:0> 50.to_s(36) > => "1e"That works really well. If you''d like something more sophisticated, you could implement Doug Crockford''s base-32 algorithm described at http://crockford.com/wrmg/base32.html . I''ve got some code for that algorithm at http://groups.google.com/group/techvalleyrb/msg/ac3ce4ae6620268a that I probably should put into a gem... Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.