A UUID (universally unique identifier) is an identifier standard used in software construction. A UUID is simply a 128-bit value. The meaning of each bit is defined by any of several variants.
For human-readable display, many systems use a canonical format using hexadecimal text with inserted hyphen characters. For example: de305d54-75b4-431b-adb2-eb6b9e546013.
The intent of UUIDs is to enable distributed systems to uniquely identify information without significant central coordination.
To use UUID as Primary Key you need to add uuidtools gem to your app’s Gemfile:
Setting up UUID as Primary Key
To set UUID as Primary Key, you need to set id to false and the new UUID column as Primary Key in migration file:
1 2 3 4 5 6 7 8 9 10
Inserting UUID Value into UUID Column
Create UUID helper library in app/lib directory:
1 2 3 4 5 6 7 8 9 10 11
And then include UuidHelper library in Model file:
1 2 3