Ruby test

Ruby code posted by Anton
created at 18 Dec 20:52

Edit | Back
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class ItemImage < ApplicationRecord
  PROCESS_JOB = FileProcessJob

  belongs_to :item

  has_attached_file :file
  validates_attachment_presence :file, unless: :processing?
  validates_attachment_content_type :file, content_type: /\Aimage\/.*\z/, if: :file_present?

  after_commit :process_file_async, on: [:create, :update], if: :should_be_processed?

  scope :processed,   -> { where.not(file_file_name: nil) }
  scope :unprocessed, -> { where(file_file_name: nil) }

  def processing?
    !processed?
  end
end
532 Bytes in 5 ms with coderay