Skip to content

Instantly share code, notes, and snippets.

@mattlenz
Created July 17, 2012 02:05
Show Gist options
  • Save mattlenz/3126520 to your computer and use it in GitHub Desktop.
Save mattlenz/3126520 to your computer and use it in GitHub Desktop.
Tiny ID
module TinyId
extend ActiveSupport::Concern
module ClassMethods
def base
Radix::BASE::B62
end
def find_by_tiny_id(string)
find(string.b(self.base.length).to_i)
end
end
def tiny_id
id.b(self.class.base.length).to_s(self.class.base)
end
end
# gem 'radix'
# class Post < ActiveRecord::Base
# include TinyId
# end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment