Friday, December 23, 2011

[Rails] Re: COUPON CODE GENERATION

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 ;-)

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

On Dec 20, 2:06 pm, Muruga <murugu2...@gmail.com> wrote:
> 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.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate