Skip to content

Instantly share code, notes, and snippets.

@jasdeepsingh
Created November 3, 2011 00:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasdeepsingh/1335378 to your computer and use it in GitHub Desktop.
Save jasdeepsingh/1335378 to your computer and use it in GitHub Desktop.
Deal Model
class Deal < ActiveRecord::Base
# Associations
has_and_belongs_to_many :stores
belongs_to :user, :class_name => "User", :foreign_key => "merchant_id"
has_many :punches
# To-do: Validations
# Add validations on the deals model
# Callbacks
before_create :setup_qr_code
serialize :qr_blob
def setup_qr_code
## Concatenate Deal ID, User ID, Store ID and Store Name and then take MD5
# of this string, this goes into the DB as QR Code
encrypted_string = ActiveSupport::SecureRandom.hex(13)
self.qr_code = encrypted_string.encode('UTF-8')
## Now, using the above QR Code, create the QR Blob and save it in the
# Database
qr_blob = RQRCode::QRCode.new(self.qr_code)
self.qr_blob = qr_blob
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment