|
- class Document < ApplicationRecord
- belongs_to :user
- belongs_to :category
- has_one :content, dependent: :destroy, required: false
- has_and_belongs_to_many :tags
-
- has_attached_file :doc,
- {
- styles: { thumb: ["200x", :png] },
- adapter_options: { hash_digest: Digest::SHA256 },
- url: "/system/:class/:attachment/:id_partition/:style/:hash.:extension",
- hash_secret: Rails.application.secrets.secret_key_base
- }
- validates_attachment_content_type :doc, content_type: 'application/pdf'
-
- after_save :generate_content
-
- scope :contains_word, -> (word) { joins(:content).where("text like ?", "%#{word}%") }
- scope :belongs_to_category, -> (category_id) { where(category_id: category_id ) }
-
- private
- def generate_content
- if self.doc_content_type == 'application/pdf'
- ContentGenerationJob.perform_now self.id
- end
- end
- end
|