首页 文章

Paperclip,CKEditor validates_attachment_content_type错误

提问于
浏览
2

当我使用paperclip从ckeditor上传图像时,我的控制台日志会进入无限循环,最后会显示消息

@extensions=["jpeg", "jpg", "jpe"]>] from Extension), content type discovered from file command: . See documentation to allow this combination.

我可以通过使用paperclip v3并从picture.rb中删除'validates_attachment_content_type'来解决这个问题 .

但我不想为图片禁用内容类型验证 .

  • 操作系统:Windows 10

  • Rails:4.1.8

  • Ruby:2.1.5

  • 回形针:4.3.2

  • Ckeditor:4.1.5

1 回答

  • 1

    我们使用以下模型在 Rails 4.2.5 中使用 CKEditorPaperclip (也许它会对您有帮助):

    #app/models/ckeditor/asset.rb
    class Ckeditor::Asset < ActiveRecord::Base
      include Ckeditor::Orm::ActiveRecord::AssetBase
      include Ckeditor::Backend::Paperclip
    
      ##### Custom stuff here #####
    end
    
    #app/models/ckeditor/picture.rb
    class Ckeditor::Picture < Ckeditor::Asset
    
      #Original
      ############
      has_attached_file :data,
                        :url  => "/ckeditor_assets/pictures/:id/:style_:basename.:extension",
                        :path => ":rails_root/public/ckeditor_assets/pictures/:id/:style_:basename.:extension",
                        :styles => { :content => '800>', :thumb => '118x100#' }
    
      validates_attachment_presence     :data
      validates_attachment_size         :data, :less_than => 5.megabytes
      validates_attachment_content_type :data, :content_type => /\Aimage/
    
      def url_content
        url(:content)
      end
    end
    

    我上次检查时效果很好:

    enter image description here

相关问题