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.
 
 
 
 
 

28 line
868 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. styles: { thumb: ["200x", :png] },
  9. adapter_options: { hash_digest: Digest::SHA256 },
  10. url: "/system/:class/:attachment/:id_partition/:style/:hash.:extension",
  11. hash_secret: Rails.application.secrets.secret_key_base
  12. }
  13. validates_attachment_content_type :doc, content_type: 'application/pdf'
  14. after_save :generate_content
  15. scope :contains_word, -> (word) { joins(:content).where("text like ?", "%#{word}%") }
  16. scope :belongs_to_category, -> (category_id) { where(category_id: category_id ) }
  17. private
  18. def generate_content
  19. if self.doc_content_type == 'application/pdf'
  20. ContentGenerationJob.perform_now self.id
  21. end
  22. end
  23. end