payrejardi_app/app/models/contact_file.rb
Nicolas Bally 3233232f4e initial
2019-02-01 12:07:55 +01: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