Last active
August 2, 2017 20:54
-
-
Save asvetly/c4216b2b5dd41de86780d20548fa25ee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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