【问题标题】:Issue while using Cloudinary, Carrierwave, Ckeditor with Rails Admin在 Rails Admin 中使用 Cloudinary、Carrierwave、Ckeditor 时出现问题
【发布时间】:2012-09-15 07:48:10
【问题描述】:

我正在尝试将 Ckeditor 与 Rails Admin 一起使用,我将 Carrierwave 和云存储用作 Cloudinary。完成所有我可以看到的设置后,CKeditor 能够将文件保存在本地存储中,然后它会创建一个 Cloudinary URL,其中应该实际存储图像。但问题是图像没有从该本地文件夹上传到 Cloudinary,而我的简单文件上传工作正常,没有任何问题。

我在这里还有一个问题 - 当我使用 Cloudinary 时,存储名称应该是什么?至于文件和 Amazon S3,我们有文件和 s3 的名称。

请回复。

谢谢

【问题讨论】:

    标签: ckeditor carrierwave rails-admin cloudinary


    【解决方案1】:

    Cloudinary 的 Ruby GEM 包含一个 CarrierWave 插件,我们的许多客户都在使用该插件。我们不知道 Ckeditor 的特殊问题(但我们尚未对其进行测试)。

    当您使用 Cloudinary 的 CarrierWave 插件时,只需将 include Cloudinary::CarrierWave 添加到您的上传器类。它将 Cloudinary 定义为存储引擎和图像处理服务(两者都是基于云的)。只需注释掉您的上传程序类中的storage :file 行。所有图片都将直接上传到 Cloudinary,所有转换后的版本都将使用 Cloudinary URL 生成。

    请查看文档页面中的示例上传器代码: http://cloudinary.com/documentation/rails_integration#carrierwave_upload

    如果问题仍然存在,如果您可以分享您的上传器代码,我们会帮助您确保其定义正确。

    【讨论】:

    • 很抱歉没有回复。是的,这是代码,我已经粘贴了上传的载波以及我用于 CKEditor 的载波。请注意,如果我从 Ckeditor 上传器中删除 Storeage :file,我会收到错误并且无法继续。 gist.github.com/3845063
    【解决方案2】:

    确保删除对 CarrierWave.config.storage = :file 的所有引用

    如果上传不起作用,您需要在几个地方执行此操作:

    在 /config/initializers/carrierwave_init.rb 中删除所有引用:

    config.storage = :file
    

    在您的上传者中删除和引用的排序:

    storage :file
    

    【讨论】:

      【解决方案3】:

      我也有 ckeditor 的问题。编辑您的 CkeditorAttachmentFileUploader 使其看起来与此类似:

      class CkeditorAttachmentFileUploader < CarrierWave::Uploader::Base
        include Ckeditor::Backend::CarrierWave
        include Cloudinary::CarrierWave
      
        [:extract_content_type, :extract_size, :extract_dimensions].each do |method|
          define_method :"#{method}_with_cloudinary" do
            send(:"#{method}_without_cloudinary") if self.file.is_a?(CarrierWave::SanitizedFile)
            {}
          end
          alias_method :"#{method}_without_cloudinary", method
          alias_method method, :"#{method}_with_cloudinary"
        end
      
        def extension_white_list
          Ckeditor.attachment_file_types
        end
      end
      

      之后,你会发现另一个错误。 我发现在Ckeditor::AssetResponse#asset_url 方法,asset 对象不会重新加载,所以asset.content_url 将始终为 nil 从而导致错误。我是这样修复的:

      class Ckeditor::Picture < Ckeditor::Asset
        ...
        def url_content
          url(:content) || begin
            if persisted?
              reload
              url(:content)
            end
          end
        end
      end
      

      如果你有 Ckeditor::AttachmentFile 类,同样如此。

      【讨论】:

        猜你喜欢
        • 2013-06-17
        • 2015-10-22
        • 2022-01-14
        • 2018-06-09
        • 2016-12-22
        • 2023-03-24
        • 2023-03-03
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多