Rails 3: Generate unique codes (coupons)

后端 未结 6 1180
借酒劲吻你
借酒劲吻你 2021-01-30 18:29

What\'s the best way to generate unique codes to use as coupon codes?

Thanks.

6条回答
  •  说谎
    说谎 (楼主)
    2021-01-30 19:01

    Maybe try this, seems to be more proof than just generating some random key. They say: UUID generator for producing universally unique identifiers based on RFC 4122 (http://www.ietf.org/rfc/rfc4122.txt). http://rubygems.org/gems/uuid

    gem install uuid
    cd /myproject/path
    uuid-setup
    

    In your code

    require_gem 'uuid'
    my_unique_id_var = UUID.new
    

    Reference: http://railsforum.com/viewtopic.php?id=12616#p44545

提交回复
热议问题