blob: c305be237a2bd8e95c765b9dc4ef82ff0d5e0c97 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# frozen_string_literal: true
# A non-activerecord helper class for csv upload
class Admin::Import
extend ActiveModel::Callbacks
include ActiveModel::Model
include Paperclip::Glue
FILE_TYPES = %w(text/plain text/csv application/csv).freeze
# Paperclip required callbacks
define_model_callbacks :save, only: [:after]
define_model_callbacks :destroy, only: [:before, :after]
attr_accessor :data_file_name, :data_content_type
has_attached_file :data
validates_attachment_content_type :data, content_type: FILE_TYPES
validates_attachment_presence :data
validates_with AdminImportValidator, on: :create
def save
run_callbacks :save
end
def destroy
run_callbacks :destroy
end
end
|