eBooru/app/models/api_key.rb
Earlopain fc7d84affd
[RuboCop] Enable Style/FrozenStringLiteralComment
This reduces allocations on the posts page by about 5%, from basic testing
2024-02-25 18:15:55 +01:00

18 lines
304 B
Ruby

# frozen_string_literal: true
class ApiKey < ApplicationRecord
belongs_to :user
validates :user_id, uniqueness: true
validates :key, uniqueness: true
has_secure_token :key
def self.generate!(user)
create(:user_id => user.id)
end
def regenerate!
regenerate_key
save
end
end