1

上传 pdf 时出现错误:未捕获的 TypeError:无法读取 null 的属性“0”

我的配置 js:

 $(function(){
  var csrf_token = $('meta[name=csrf-token]').attr('content');
  var csrf_param = $('meta[name=csrf-param]').attr('content');
  var params;
  if (csrf_param !== undefined && csrf_token !== undefined) {
   params = csrf_param + "=" + encodeURIComponent(csrf_token);
  } 
  $('.redactor').redactor(
   { "imageUpload":"/redactor_rails/pictures?" + params,
     "fileUpload":"/redactor_rails/documents?" + params,
     "imageGetJson":"/redactor_rails/pictures",
     "path":"/assets/redactor-rails",
     "css":"style.css"}
  );

});

RedactorRailsDocumentUploader:

  class RedactorRailsDocumentUploader < CarrierWave::Uploader::Base
   include RedactorRails::Backend::CarrierWave

   # storage :fog
   storage :file

   def store_dir
    "system/redactor_assets/documents/#{model.id}"
   end

   def extension_white_list
     RedactorRails.document_file_types
   end
  end
4

1 回答 1

0

我怀疑这是因为您的RedactorRails.document_file_types.

在 redactor-rails gem 中,它仅列出“pdf”,而不是“PDF”、“Pdf”等。请参见此处的第 23 行:https ://github.com/SammyLin/redactor-rails/blob/master/lib/redactor-轨道.rb

除非您对此有安全需要,否则我会注释掉:

   def extension_white_list
     RedactorRails.document_file_types
   end
于 2013-11-29T14:19:48.813 回答