Skip to content

Instantly share code, notes, and snippets.

@sco
Created April 21, 2009 15:48
Show Gist options
  • Select an option

  • Save sco/99202 to your computer and use it in GitHub Desktop.

Select an option

Save sco/99202 to your computer and use it in GitHub Desktop.
class Order < ActiveRecord::Base
SECRET = '3a9392e86049546fcff5e21e3c89564deb8bd9d4'
def self.find_by_token(token)
id, sig = token.split('-')
record = find(id)
if record.nil? || token != record.token
raise ActiveRecord::RecordNotFound, "invalid sig"
end
record
end
def token
sig = Digest::SHA1.hexdigest(id.to_s + SECRET)[0, 9]
[id, sig].join('-')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment