2017-04-10 1 views
0

나는 ckeditor를 cloudinary와 함께 사용하는 레일 4에 프로젝트를 가지고 있습니다. Cloudinary에 uplaod는 잘 작동하지만 에디터가 이미지를 젊은이시기를 업로드 한 후, 나는 오류 얻을 :레일 4 : CKEditor gsub 오류

NoMethodError - undefined method `gsub' for nil:NilClass: 

enter image description here

내 CKEditor 사진 업 로더는 다음과 같습니다

# encoding: utf-8 
class CkeditorPictureUploader < CarrierWave::Uploader::Base 
    include Ckeditor::Backend::CarrierWave 
    include Cloudinary::CarrierWave 
    include CarrierWave::MiniMagick 



    [:extract_content_type, :set_size, :read_dimensions].each do |method| 
    define_method :"#{method}_with_cloudinary" do 
     send(:"#{method}_without_cloudinary") if self.file.is_a?(CarrierWave::SanitizedFile) 
     {} 
    end 
    alias_method_chain method, :cloudinary 
    end 

    process :read_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 

을 업로드하고 "서버에서 이미지 찾기"를 클릭하면 이미지가 있고 편집기에 이미지를로드 할 수 있지만 이미지를 서버에 업로드 할 수 없습니다.

누군가이 문제가있어?

감사합니다.

답변

0

이 오류는 gsub이 (가) 업로드 된 이미지의 URL을 ckeditor에서 찾을 수 없기 때문에 발생합니다. 당신은 당신의 응용 프로그램의 당신의 lib 디렉토리/ckeditor 폴더에 ckeditor asset_response.rb 파일을 만들고

def asset_url(relative_url_root) 
    @ckeditor_assets = Ckeditor::Picture.last.url_content 
    puts @ckeditor_assets.inspect 
    #return nil if asset.url_content.nil? 
    url = @ckeditor_assets #Ckeditor::Utils.escape_single_quotes(asset.url_content) 

    if URI(url).relative? 
    "#{relative_url_root}#{url}" 
    else 
    url 
    end 
end 

전체 코드를 넣어 코드 행을 넣어이 함께 ASSET_URL 방법을 교체해야합니다. 이것은 Ckeditor::Picture 모델을 포함하는 해킹 일뿐입니다.

는 CkeditorPictureUploader 파일에 cloudinary에 대한

include Ckeditor::Backend::CarrierWave 
include Cloudinary::CarrierWave 
    process :tags => ["photo_album_sample"] 
    process :convert => "jpg" 
    version :thumbnail do 
    eager 
    resize_to_fit(200, 200) 
    cloudinary_transformation :quality => 80   
    end 
+0

덕분에이 코드를 넣어! lib/ckeditor 폴더는 없습니다. 나는 하나 만들어야 하나? –

+0

방금 ​​libs/ckeditor/asset_response.rb 파일을 만들고 거기에 코드를 넣으려고했습니다. 그러나 나는 여전히 같은 오류를 낳았다. 내 프로젝트에서 보석의 CKEDITOR 폴더를 찾을 수 없으므로 프로젝트의 LIB 폴더에이 파일을 생성해야한다고 생각합니까? –

+0

예'lib' ckeditor/asset_response.rb 파일에 폴더를 만들고 ckeditor 폴더가 모델에 있는지 확인해야합니다. –