Skip to content

Instantly share code, notes, and snippets.

@asvetly
Last active August 2, 2017 20:54
Show Gist options
  • Save asvetly/c4216b2b5dd41de86780d20548fa25ee to your computer and use it in GitHub Desktop.
Save asvetly/c4216b2b5dd41de86780d20548fa25ee to your computer and use it in GitHub Desktop.
#fish shell
echo >> test.rb "\
class User < ApplicationRecord
# Assign an API key on create
before_create do |user|
user.api_key = user.generate_api_key
end
# Generate a unique API key
def generate_api_key
loop do
token = SecureRandom.base64.tr('+/=', 'Qrt')
break token unless User.exists?(api_key: token)
end
end
end"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment