UniqueToken
Rails gem for generating a unique token in an Active Record model.
Install
gem install unique_token
Usage
Let’s say you have a Project model with a “token” string column that you want to be a unique identifier. Just add this to your model.
class Project < ActiveRecord::Base unique_token :token end
This will generate a random and unique string before each book is created.
You can specify multiple columns and options like this.
uniquify :token, :salt, :length => 12, :chars => 0..9
You can also pass a block to generate your own characters.
uniquify :token do rand(99999) end