Skip to content

Instantly share code, notes, and snippets.

@ivanvanderbyl
Last active February 2, 2017 10:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivanvanderbyl/6f459bb16431064e5886013f1e29a22f to your computer and use it in GitHub Desktop.
Save ivanvanderbyl/6f459bb16431064e5886013f1e29a22f to your computer and use it in GitHub Desktop.
class Booking < ActiveRecord::Model
after_create :set_booking_number
private
def set_booking_number
return if booking_number
update_column(:booking_number, SecureRandom.hex[0..5].upcase)
rescue ActiveRecord::RecordNotUnique
retry
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment