Adds redemption capability to a model for items like coupons, invitation codes, etc.
Ruby
Switch branches/tags
Nothing to show
Pull request Compare This branch is 1 commit behind squeejee:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
test
MIT-LICENSE
README.textile
Rakefile
init.rb
install.rb
uninstall.rb

README.textile

ActsAsRedeemable

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.

Usage

Optionally generate the model

script/generate redeemable Coupon rake db:migrate

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
end

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