Skip to content

Instantly share code, notes, and snippets.

@ptb
Last active December 19, 2015 02:59
Show Gist options
  • Select an option

  • Save ptb/5886864 to your computer and use it in GitHub Desktop.

Select an option

Save ptb/5886864 to your computer and use it in GitHub Desktop.
token based ActiveRecord
SEED = 12345678901
def self.find_by_token(token)
id = token.reverse.to_i(36) - Thing::SEED
find(id)
end
def token(input = self.to_param)
(input.to_i + Thing::SEED).to_s(36).reverse
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment