rails 5.1.4 红宝石2.4.1 ckeditor 4.2.4 carrierwave 1.2.2 minimagick 4.8.0 fog-aws 2.0.1
我有carwave支持的ckeditor,它连接到S3存储桶。图像正在上传到S3存储桶。我可以看到那里的文件!但是ckeditor屏幕冻结了,这是heroku logs.rails服务器的输出给出了同样的错误。 这绝对是一个ckeditor配置问题,因为我可以通过照片上传器上传封面照片,其中ckeditor不是中间人。它只是一个使用carrierwave和S3的html文件字段。我能够回忆起封面照片,并从S3桶中显示出来,所以我知道我的凭据是好的。
HEROKU日志:
Started POST "/ckeditor/pictures?&CKEditor=ckeditor&CKEditorFuncNum=1&langCode=en" for IP ADDRESS
Processing by Ckeditor::PicturesController#create as HTML
Parameters: {"upload"=>#<ActionDispatch::Http::UploadedFile:0x000000038f2868 @tempfile=#<Tempfile:/tmp/RackMultipart20180315-4-1xodi16.jpg>, @original_filename="coloursquare.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"upload\"; filename=\"coloursquare.jpg\"\r\nContent-Type: image/jpeg\r\n">, "ckCsrfToken"=>"56COpAWYrezg8OINmQYCmH6Hr1I5ZVxy1u9YtFmP", "CKEditor"=>"ckeditor", "CKEditorFuncNum"=>"1", "langCode"=>"en"}
DEBUG --
DEBUG -- SQL INSERT INTO "ckeditor_assets" ("data_file_name", "data_content_type", "data_file_size", "type", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6) RETURNING "id"[0m [["data_file_name", "coloursquare.jpg"], ["data_content_type", "image/jpeg"], ["data_file_size", 12893], ["type", "Ckeditor::Picture"], ["created_at", "2018-03-15 23:25:06.970758"], ["updated_at", "2018-03-15 23:25:06.970758"]]
heroku[router]: at=info method=POST path="/ckeditor/pictures?&CKEditor=ckeditor&CKEditorFuncNum=1&langCode=en" host=stormy-hollows-12083.herokuapp.com request_id=0e9fd60d-685e-4cd5-9296-413b68e0bf45 fwd="73.96.105.72" dyno=web.1 connect=0ms service=274ms status=500 bytes=1825 protocol=https
DEBUG -- COMMIT
INFO -- Completed 401 Unauthorized in 261ms (ActiveRecord: 27.2ms)
FATAL --
FATAL -- : ArgumentError (Version content doesn't exist!):
FATAL --
FATAL -- : app/models/ckeditor/asset.rb:4:in `url'
app/models/ckeditor/picture.rb:5:in `url_content'
CKEDITOR PICTURE UPLOADER.rb
class CkeditorPictureUploader < CarrierWave::Uploader::Base
include Ckeditor::Backend::CarrierWave
include CarrierWave::MiniMagick
storage :fog
def store_dir
"uploads/ckeditor/pictures/#{model.id}"
end
def default_url
"/images/fallback/" + [version_name, "default.png"].compact.join('_')
end
def content_type_blacklist
['application/text', 'application/json']
end
def extension_white_list
Ckeditor.image_file_types
end
def content_type_blacklist
['application/text', 'application/json']
end
end
CKEDITOR config.js
CKEDITOR.editorConfig = function( config ) {
config.language = 'en';
config.uiColor = '#ffffff';
config.pasteFromWordRemoveStyles = false;
config.filebrowserBrowseUrl = "/ckeditor/attachment_files";
config.filebrowserFlashBrowseUrl = "/ckeditor/attachment_files";
config.filebrowserFlashUploadUrl = "/ckeditor/attachment_files";
config.filebrowserImageBrowseLinkUrl = "/ckeditor/pictures";
config.filebrowserImageBrowseUrl = "/ckeditor/pictures";
config.filebrowserImageUploadUrl = "/ckeditor/pictures?";
config.filebrowserUploadUrl = "/ckeditor/attachment_files";
config.allowedContent = true;
}
MODEL CKEDITOR asset.rb
class Ckeditor::Asset < ActiveRecord::Base
include Ckeditor::Orm::ActiveRecord::AssetBase
delegate :url, :current_path, :content_type, to: :data
validates :data, presence: true
end
MODEL CKEDITOR picture.rb
class Ckeditor::Picture < Ckeditor::Asset
mount_uploader :data, CkeditorPictureUploader, mount_on: :data_file_name
def url_content
url(:content)
end
end
答案 0 :(得分:0)
我在Ckeditor::AssetResponse#asset_url中找到了
方法,asset
对象不会重新加载,因此asset.content_url
将始终为零,从而导致错误。我这样修好了:
class Ckeditor::Picture < Ckeditor::Asset
...
def url_content
url(:content) || begin
if persisted?
reload
url(:content)
end
end
end
end
同样适用于Ckeditor::AttachmentFile
课程。