Grigor Aleksanyan
Grigor Aleksanyan

Reputation: 550

Paperclip, CKEditor validates_attachment_content_type error

When I upload an image from ckeditor with paperclip, my console logs goes to infinity loop and in the end it shows message

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

I can resolve this by using paperclip v3 and removing 'validates_attachment_content_type' from picture.rb.

But I don't want disable content type validation for pictures.

Upvotes: 2

Views: 344

Answers (1)

Richard Peck
Richard Peck

Reputation: 76784

We use CKEditor with Paperclip in Rails 4.2.5 using the following model (maybe it will help you):

#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

It worked well last time I checked:

enter image description here

Upvotes: 1

Related Questions