[英]CKEDITOR + CARRIERWAVE + S3 no image
I can't figure out why the heck CKEDITOR is not displaying my images...I am using Carrierwave as my uploader to S3, which obviously have been set to all have their own 'uploader.rb' If I upload directly through Carrierwave I have no problems retrieving said image back from S3 to display. 我不知道为什么CKEDITOR不能显示我的图像...我将Carrierwave用作S3的上传器,显然已经设置为各自拥有自己的“ uploader.rb”。如果我直接通过Carrierwave上传,我从S3取回所述图像以进行显示没有问题。 BUT if I upload said image through CKEDITOR or attach it inside CKEDITOR it will only display it's source link. 但是,如果我通过CKEDITOR上传图片或将其附加到CKEDITOR内,它将仅显示其源链接。 This happens in both production and dev localhost. 在生产环境和开发本地主机中都会发生这种情况。
uploaders/ckeditor_attachement_file_uploader.rb 上传/ ckeditor_attachement_file_uploader.rb
# encoding: utf-8
require 'carrierwave'
class CkeditorAttachmentFileUploader < CarrierWave::Uploader::Base
include Ckeditor::Backend::CarrierWave
# Include RMagick or ImageScience support:
# include CarrierWave::RMagick
# include CarrierWave::MiniMagick
# include CarrierWave::ImageScience
# Choose what kind of storage to use for this uploader:
if Rails.env.production?
storage :fog
else
storage :file
end
# Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted:
def store_dir
"uploads/ckeditor/attachments/#{model.id}"
end
# Provide a default URL as a default if there hasn't been a file uploaded:
# def default_url
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
# end
# Process files as they are uploaded:
# process :scale => [200, 300]
#
# def scale(width, height)
# # do something
# end
# Add a white list of extensions which are allowed to be uploaded.
# For images you might use something like this:
def extension_white_list
Ckeditor.attachment_file_types
end
end
uploaders/ckeditor_picture_uploader.rb 上传/ ckeditor_picture_uploader.rb
# encoding: utf-8
class CkeditorPictureUploader < CarrierWave::Uploader::Base
include Ckeditor::Backend::CarrierWave
# Include RMagick or ImageScience support:
# include CarrierWave::RMagick
include CarrierWave::MiniMagick
# include CarrierWave::ImageScience
# Choose what kind of storage to use for this uploader:
if Rails.env.production?
storage :fog
else
storage :file
end
# Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted:
def store_dir
"uploads/ckeditor/pictures/#{model.id}"
end
# Provide a default URL as a default if there hasn't been a file uploaded:
# def default_url
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
# end
# Process files as they are uploaded:
# process scale: [200, 300]
#
# def scale(width, height)
# # do something
# end
process :extract_dimensions
# Create different versions of your uploaded files:
version :thumb do
process resize_to_fill: [118, 100]
end
version :content do
process resize_to_limit: [800, 800]
end
# Add a white list of extensions which are allowed to be uploaded.
# For images you might use something like this:
def extension_white_list
Ckeditor.image_file_types
end
end
models/picture.rb 车型/ picture.rb
class Ckeditor::Picture < Ckeditor::Asset
mount_uploader :data, CkeditorPictureUploader, mount_on: :data_file_name
def url_content
url(:content)
end
end
models/attachement_file.rb 车型/ attachement_file.rb
class Ckeditor::AttachmentFile < Ckeditor::Asset
mount_uploader :data, CkeditorAttachmentFileUploader, mount_on: :data_file_name
def url_thumb
@url_thumb ||= Ckeditor::Utils.filethumb(filename)
end
end
I know I am answering my own question but hopefully this will help you. 我知道我正在回答自己的问题,但希望这会对您有所帮助。 If you are reading this then you obviously have all your storage set up correctly such as S3 (in my case). 如果您正在阅读本文,那么显然您已正确设置了所有存储,例如S3(在我的情况下)。 Your views must require the html_safe method when attempting to display your contents via ckeditor ex. 尝试通过ckeditor ex显示内容时,视图必须要求html_safe方法。
<div class="col-xs-12">
<h1>Webur Blog</h1>
<h2><%= @blogpost.title %></h2>
<span><p><%= image_tag @blogpost.picture.url if @blogpost.picture? %></p></span>
<p><%= @blogpost.content.html_safe %></p>
<% if is_an_admin %>
<%= link_to "Return to blog", blogposts_path, class: 'btn btn-primary' %>
<%= link_to "Edit Post", edit_blogpost_path, class: 'btn btn-primary' %> |
<%= link_to "Delete Post", blogpost_path(@blogpost),
method: :delete, data: {confirm: "Are you sure?"}, class: 'btn btn-danger' %>
<% else %>
<%= link_to "Return to blog", blogposts_path, class: 'btn btn primary' %>
<% end %>
</div>
Hopefully this helps others. 希望这对其他人有帮助。 CKeditor does not mention this in their setup guide, and if you are a beginner such as myself you may not catch subtleties like this CKeditor在他们的安装指南中没有提到这一点,如果您是像我这样的初学者,则可能不会像这样微妙
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.