COUPON CODE GENERATION

Hey all
        I was working an app that is integrated with credit card
payment.I want to generate a coupon code and give it to some users so
that they will get some discounts while subscribing.Please help
me...Thanks in advance.

Hi Muruga,

We did some thing similar. I have extracted the coupon code generation
into a gem. You may find it at https://github.com/bvsatyaram/random_password_generator
This must meet any requirement you need for coupon code generation.
Let me know if you don't see a requirement met :wink:

We didn't actually work on discount coupon, but on beta invites. Users
can signup for beta using beta key. The following is minorly tweaked
model.

class BetaInvite < ActiveRecord::Base
  belongs_to :sender, :class_name => User.name
  belongs_to :receiver, :class_name => User.name

  validates :beta_key, :presence => true, :uniqueness => true

  before_validation :set_beta_key, :on => :create

  # Displays the beta in a more readable format, by inserting a hyphen
after every 5th character
  def beta_key_for_display
    str = self.beta_key
    (5..24).step(6).each do |i|
      str = str.insert(i, '-')
    end

    return str
  end

  private

  def set_beta_key
    self.beta_key = generate_random_beta_key until
(self.beta_key.present? &&
BetaInvite.find_by_beta_key(self.beta_key).nil?)
  end

  def generate_random_beta_key
    RandomPasswordGenerator.generate(25, :skip_lower_case => true,
      :skip_symbols => true,
      :skip_url_unsafe => true)
  end
end

Hope this helps.

Best Regards,
Satyaram B V