Adds redemption capability to a model for items like coupons, invitation codes, etc. Each redeemable gets a unique code upon creation that can be sent in an email or printed as a coupon code.
script/generate redeemable Coupon rake db:migrate Optionally generate the model
Make your ActiveRecord model act as redeemable.
class Coupon < ActiveRecord::Base
acts_as_redeemable :valid_for => 30.days, :code_length => 8 # optional expiration, code length
Create a new instance
c = Coupon.new c.user_id = 1 # The user who created the coupon c.save c.code # "4D9110A3" c.created_at # Fri Feb 15 14:56:37 -0600 2008 c.expires_on # Fri Mar 16 14:56:37 -0600 2008
Copyright © 2008 Squeejee, released under the MIT license