akkounts/app/models/invitation.rb

18 lines
305 B
Ruby

class Invitation < ApplicationRecord
# Relations
belongs_to :user
validates_presence_of :user
before_create :generate_token
scope :unused, -> { where(used_at: nil) }
scope :used, -> { where.not(used_at: nil) }
private
def generate_token
self.token = SecureRandom.hex(8)
end
end