mercredi 26 octobre 2022

undefined method `original_filename' for #<:storage::awsfile:>

Can't seem to identify why I would be getting a undefined method original_filename. Maybe because when upgrading ruby 3.1.2,with ruby 2.7.5 can still use this method.

Uploader

class DocumentUploader < CarrierWave::Uploader::Base
  CarrierWave::SanitizedFile.sanitize_regexp = Settings.regex.upload_filename

  def store_dir
    "uploads/event_documents/#{mounted_as}/#{model.id}"
  end
end

Model

class EventDocumentFile < ActiveRecord::Base
  mount_uploader :document_file, DocumentUploader
  validate :document_file_name

  private

  def document_file_name
    return if !document_file.file.present? || document_file.file.original_filename.length <= 70
    errors.add :document_file, I18n.t("event_documents.invalid_file_name")
  end
end

Error detail

undefined method `original_filename' for #<CarrierWave::Storage::AWSFile:0x00007fe60dfc38e8 @uploader=#<DocumentUploader:0x00007fe60dfbdc18 @model=#<EventDocumentFile

return if !document_file.file.present? || document_file.file.original_filename.length <= 70
                                                            ^^^^^^^^^^^^^^^^^^

Anyone know what's wrong with my code? thanks!

Aucun commentaire:

Enregistrer un commentaire