class Import < ActiveRecord::Base mount_uploader :file, ImportUploader belongs_to :workbench belongs_to :referential belongs_to :parent, polymorphic: true extend Enumerize enumerize :status, in: %i(new pending successful failed running aborted canceled) validates :file, presence: true validates_presence_of :referential, :workbench before_create :initialize_fields def notify_parent end private def initialize_fields self.token_download = SecureRandom.urlsafe_base64 self.status = Import.status.new end end