Created
July 17, 2012 02:05
-
-
Save mattlenz/3126520 to your computer and use it in GitHub Desktop.
Tiny ID
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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