module-and-template-store/app/models/api_key.rb

17 lines
277 B
Ruby

class ApiKey
include Mongoid::Document
field :access_token, type: String
index({ access_token: 1}, { unique: true })
before_create :generate_access_token
private
def generate_access_token
begin
self.access_token = SecureRandom.hex
end
end
end