Skip to content

Instantly share code, notes, and snippets.

@JonCrawford
Created April 21, 2009 14:01
Show Gist options
  • Save JonCrawford/99156 to your computer and use it in GitHub Desktop.
Save JonCrawford/99156 to your computer and use it in GitHub Desktop.
class AddSecurityStringToOrder < ActiveRecord::Migration
def self.up
add_column :orders, :security_string, :string
end
def self.down
remove_column :orders, :security_string
end
end
...
before_create :set_security_string
def set_security_string
self.security_string = Digest::SHA1.hexdigest("#{Time.now}#{rand.to_s}")[0..15]
end
def to_param
security_string
end
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment