Skip to content

Instantly share code, notes, and snippets.

@ymendel
Created August 10, 2009 19:10
Show Gist options
  • Save ymendel/165357 to your computer and use it in GitHub Desktop.
Save ymendel/165357 to your computer and use it in GitHub Desktop.
class Invitation < ActiveRecord::Base
# Returns encoded invitation id
def encoded_id
self.id*10011981 * 1820062 - 1981
end
def self.decode_id(id)
i = ((id.to_i + 1981)/1820062)/10011981
if (i*10011981 * 1820062 - 1981)==id.to_i
begin
Invitation.find(i).id
rescue
false
end
else
false
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment