ActiveUxid is a library for generating obfuscated UXid's.
Add this line to your application's Gemfile:
And then execute:
Or install it yourself as:
$ gem install active_uxid
Table of Contents
rails generate active_uxid:install will generate the following file:
. do |config| config.encoding_chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' config.encoding_length = 26 config.encoding_salt = 1_369_136 end
# Hash ID's are reversible but less performant # than ULID ::.(10) #=> 'q5D8inm0' ::.('q5D8inm0') #=> 10
# ULID are secure as they are not reversible # They are also more performant than Hash ID's ::. #=> '1mqfg9qa96s8s5f02o1ucf8lcc'
class User < ActiveRecord::Base # Add a uxid binary attribute to the corresponding table. include :::: # Or include :::: end # Hash UXid's type only User.find_by_uxid('x123') #=> find record by uxid user = User.new user.uxid_to_id #=> decodes the records uxid to id
Your contribution is welcome.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature)
- Commit your changes (
git commit -am 'Added some feature')
- Push to the branch (
git push origin my-new-feature)
- Create new Pull Request