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