Skip to content

Instantly share code, notes, and snippets.

@nitschmann
Created August 13, 2017 12:34
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 nitschmann/f6e0a0d814dec5c4da37d9a75ac8ed06 to your computer and use it in GitHub Desktop.
Save nitschmann/f6e0a0d814dec5c4da37d9a75ac8ed06 to your computer and use it in GitHub Desktop.
uuid as primary key
module UuidAsPrimaryKey
extend ActiveSupport::Concern
included do
before_create :assign_uuid
end
protected
def assign_uuid
return if self.id.present?
self.id = SecureRandom.uuid
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment