Hashable allows you to generate and save hash id for ActiveRecord models.
For example :
ID | Hash ID |
---|---|
1 |
ejRe |
2 |
bk5e |
3 |
el5a |
Hashable uses HashIds.rb encoding.
N.B. If you don't need to save hash id in database, you can use HashId Rails.
Add this line to your application's Gemfile:
gem 'hashable', github: 'rdelandesen/hashable'
And then execute:
$ bundle
class User < ActiveRecord::Base
hashable.config do |c|
c.attr = :hash_id
# Optional
c.source = :id
c.salt = 'replaceit' # by default => ''
c.alphabet = 'abcdefxyz' # by default => all letters + 0..9
c.min_length = 4 # by default
end
end
Bug reports and pull requests are welcome on GitHub at https://github.com/rdelandesen/hashable.
The gem is available as open source under the terms of the MIT License.