Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 

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