abritium_app/app/models/contact_file.rb
Nicolas Bally a92bd4db72 initial
2019-05-08 11:30:56 +02:00

27 lines
440 B
Ruby

class ContactFile < ActiveRecord::Base
mount_uploader :file, ContactFileUploader
belongs_to :admin
belongs_to :contact
def file_type
mime = `file --mime -br "#{self.file.path}"`.strip.split(';')[0]
mime
end
before_create { generate_token() }
def generate_token()
begin
self[:token] = SecureRandom.urlsafe_base64
end while ContactFile.exists?(:token => self[:token])
end
end