You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

27 lines
746 B

  1. class Document < ApplicationRecord
  2. belongs_to :user
  3. belongs_to :category
  4. has_one :content, dependent: :destroy, required: false
  5. has_and_belongs_to_many :tags
  6. has_attached_file :doc,
  7. {
  8. adapter_options: { hash_digest: Digest::SHA256 },
  9. url: "/system/:class/:attachment/:id_partition/:style/:hash.:extension",
  10. hash_secret: Rails.application.secrets.secret_key_base
  11. }
  12. validates_attachment_content_type :doc, content_type: 'application/pdf'
  13. after_save :generate_content
  14. scope :contains_word, -> (word) { joins(:content).where("text like ?", "%#{word}%") }
  15. private
  16. def generate_content
  17. if self.doc_content_type == 'application/pdf'
  18. ContentGenerationJob.perform_now self.id
  19. end
  20. end
  21. end