Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I need to generate uuid for my rails application. What are the options(gems) I have? [duplicate]

I use Rails 3.0.20 and ruby 1.8.7 (2011-06-30 patchlevel 352)

Please suggest me the best plugin to generate guid.

like image 813
Virtual Avatar asked Aug 14 '13 09:08

Virtual


People also ask

What is UUID in Rails?

A universally unique identifier (UUID) is a 128-bit number used to identify information in computer systems. Sometimes it is referred to as a 'globally unique identifier'. These are a native column type in PostgreSQL. You can find more details on native Postgres types in the Rails Guides.

What is UUID in Ruby?

Ruby | Random uuid() function Random#uuid() : uuid() is a Random class method which checks returns a random v4 UUID (Universally Unique IDentifier). Syntax: Random.uuid() Parameter: Random values. Return: a random v4 UUID (Universally Unique IDentifier).


2 Answers

There are plenty of options, I recommend not to add additional dependencies and use SecureRandom which is builtin:

SecureRandom.uuid #=> "1ca71cd6-08c4-4855-9381-2f41aeffe59c" 

See other possible formats here.

like image 81
apneadiving Avatar answered Oct 17 '22 06:10

apneadiving


The first thing I would suggest is that please upgrade your ruby and rails version.

A very good way of generating guid is SecureRandom, which is a ruby module. With easy usage.

require 'securerandom' guid = SecureRandom.hex(10) #or whatever value you want instead of 10 
like image 45
QuestionEverything Avatar answered Oct 17 '22 07:10

QuestionEverything