Paperclip,CKEditor validates_attachment_content_type错误

时间:2015-12-12 11:05:49

标签: ruby-on-rails ruby ckeditor paperclip

当我使用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
  • Paperclip:4.3.2
  • Ckeditor:4.1.5

1 个答案:

答案 0 :(得分:1)

我们在CKEditor中使用Paperclip Rails 4.2.5使用以下模型(可能会对您有所帮助):

#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