Simple coupon generator in rails

I have working on this from quite a long time but didn't get anything useful, all i want to know is how to add a simple random coupon generator. I have a rails app where users can check offers of restaurant, salon etc now i want to add a system so that users can generate a coupon and show that coupon to avail offers.


You don't mention what sort of coupon format you require and I am sure there are a bunch of gems that do similar things. I guess one approach is to use a unique code that you can generate and then tag a user_id to the end of it to ensure uniqueness across many codes.

def generate_coupon_code(user_id)
  characters = %w(A B C D E F G H J K L M P Q R T W X Y Z 1 2 3 4 5 6 7 8 9)
  code = ''

  4.times { code << characters.sample }
  code << user_id.to_s


If you don't mind building software from cloud services then you can try to use Voucherify. They provide a library for Ruby:

require "voucherify"

voucherify ={
  "applicationId" => "YOUR-APPLICATION-ID",
  "clientSecretKey" => "YOUR-CLIENT-SECRET-KEY"

code = nil # for an automatically generated string

# single-use voucher with 10% off discount that is valid throughout the whole 2016
voucher = {
  category: "Restaurant",
  discount: {
    percent_off: 10.0,
    type: "PERCENT"
  start_date: "2016-01-01T00:00:00Z",
  expiration_date: "2016-12-31T23:59:59Z",
  redemption: {
    quantity: 1

voucherify.create(code, voucher)

Full disclosure: I'm a developer of Voucherify.

Need Your Help

Authentication in Flask app using flask-simpleldap

python authentication flask ldap flask-login

I am trying to build user authentication in Flask app. The authentication needs to be done using the LDAP server. The documentation given on this

Porting Unix ada app to Linux: Seg fault before program begins

linux unix ada

I am an intern who was offered the task of porting a test application from Solaris to Red Hat. The application is written in Ada. It works just fine on the Unix side. I compiled it on the linux sid...