justinsaul / acts_as_redeemable

Adds redemption capability to a model for items like coupons, invitation codes, etc.

Home Page:http://squeejee.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

About

Adds redemption capability to a model for items like coupons, invitation codes, etc.

http://squeejee.com

License:MIT License


Languages

Language:Ruby 100.0%