All posts

How to generate uuids in a Ruby on Rails application

Have you decided to use universally unique identifiers instead of auto incrementing integers for primary keys in your database table?

You can generate those UUID’s using SecureRandom.uuid

=> SecureRandom.uuid

Tip: I cover creating a table with a non-id primary key in this post.

If you need to exchange a unique identifier with another system, there is another method to handle that, SecureRandom.urlsafe_base64. To learn more about URL safe strings, you can check out this Stack Overflow answer.

=> SecureRandom.urlsafe_base64