Created
November 3, 2011 00:07
-
-
Save jasdeepsingh/1335378 to your computer and use it in GitHub Desktop.
Deal Model
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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