2017-05-02 2 views
0

CKEDITOR가 내 이미지를 표시하지 않는 이유를 알 수 없습니다. S3에 업 로더로 Carrierwave를 사용하고 있습니다. 분명히 모든 사용자에게 '업 로더가 있습니다. .rb 'Carrierwave를 통해 직접 업로드하는 경우 이미지를 S3에서 다시 표시하는 데 문제가 없습니다. 그러나 이미지를 CKEDITOR를 통해 업로드하거나 CKEDITOR에 첨부하면 원본 링크 만 표시됩니다. 이것은 프로덕션 및 dev 로컬 호스트에서 발생합니다.CKEDITOR + CARRIERWAVE + S3 이미지 없음

업 로더/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 

업 로더/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 

모델/picture.rb

class Ckeditor::Picture < Ckeditor::Asset 
    mount_uploader :data, CkeditorPictureUploader, mount_on: :data_file_name 

    def url_content 
    url(:content) 
    end 
end 

모델/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 
+0

나는 수수께끼를 풀었고, 내 견해에는 html_safe가 필요했습니다. 예 :

<% = @ blogpost.content.html_safe %>

생산에 넣었을 때만 알아 냈을뿐 아니라 HTML 마크 업을 표시하는 것으로 나타났습니다. –

답변

0

나는 내 자신의 질문에 대답하고 있지만 잘하면이 도움이 될 것입니다. 이 글을 읽는다면 분명 S3 (내 경우에는)와 같이 모든 스토리지를 올바르게 설정할 수 있습니다. 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> 

다른 사람들에게 도움이되기를 바랍니다. CKeditor는 설정 안내서에서이 점을 언급하지 않았고, 자신과 같은 초보자라면 이처럼 미묘함을 잡지 못할 수도 있습니다.