1

宝石 => https://github.com/galetahub/ckeditor

导轨 = 4.1.4

我已经搞定了

rails generate ckeditor:install --orm=active_record --backend=dragonfly

ckeditor_dragonfly.rb

# Load Dragonfly for Rails if it isn't loaded already.
require "dragonfly/rails/images"

# Use a separate Dragonfly "app" for CKEditor.
app = Dragonfly[:ckeditor]
app.configure_with(:rails)
app.configure_with(:imagemagick)

# Define the ckeditor_file_accessor macro.
app.define_macro(ActiveRecord::Base, :ckeditor_file_accessor) if defined?(ActiveRecord::Base)
app.define_macro_on_include(Mongoid::Document, :ckeditor_file_accessor) if defined?(Mongoid::Document)

app.configure do |c|
  # Store files in public/uploads/ckeditor. This is not
  # mandatory and the files don't even have to be stored under
  # public. If not storing under public then set server_root to nil.
  c.datastore.root_path = Rails.root.join("public", "uploads", "ckeditor", Rails.env).to_s
  c.datastore.server_root = Rails.root.join("public").to_s

  # Accept asset requests on /ckeditor_assets. Again, this is not
  # mandatory. Just be sure to include :job somewhere.
  c.url_format = "/uploads/ckeditor/:job/:basename.:format"
end

# Insert our Dragonfly "app" into the stack.
Rails.application.middleware.insert_after Rack::Cache, Dragonfly::Middleware, :ckeditor

但是当我尝试做某事时,一个错误:

Dragonfly::App[:ckeditor] is deprecated - use Dragonfly.app (for the default app) or Dragonfly.app(:ckeditor) (for extra named apps) instead. See docs at http://markevans.github.io/dragonfly for details

NoMethodError: undefined method `configure_with' for Dragonfly:Module

有什么想法可以解决问题?

升级版。如果更正这些错误,则变为:

Dragonfly::Configurable::UnregisteredPlugin: plugin :rails is not registered
4

2 回答 2

0

Eraden,您的示例有效。我已经用您提供的内容替换了 ckeditor_dragonfly.rb 的内容,然后“rake db:migrate”终于成功了。

但是当我上传图片时,我得到:

NoMethodError(未定义的方法ckeditor_file_accessor' for #<Class:0x007fb92c720118>): app/models/ckeditor/asset.rb:5:in'app/models/ckeditor/asset.rb:1:in <top (required)>' app/models/ckeditor/picture.rb:1:in'

看来,您需要将 /app/model/ckeditor/asset.rb 中的“ckeditor_file_accessor :data”替换为“dragonfly_accessor :data”。这为我解决了这个特殊的错误,虽然我有另一个错误,但它似乎与讨论的主题无关。

(只是为了这种情况,我把这个问题写在这里:

DRAGONFLY:验证数据的属性格式失败,错误命令失败('identify''-ping''-format''%m %w %h''/var/folders/x6/pwnc5kls5d17z4j715t45jkr0000gr/T/RackMultipart20150406-2109-1ho7120 ') 退出状态和 stderr dyld:库未加载:/usr/local/lib/liblzma.5.dylib 引用自:/usr/local/bin/identify 原因:找不到图像

)

于 2015-04-06T15:47:31.970 回答
0

删除所有 ckeditor 初始化程序。

添加具有以下内容的新文件:

require 'dragonfly'

# Logger
Dragonfly.logger = Rails.logger

# Add model functionality
if defined?(ActiveRecord::Base)
  ActiveRecord::Base.extend Dragonfly::Model
  ActiveRecord::Base.extend Dragonfly::Model::Validations
end

Dragonfly.app(:ckeditor).configure do

  # this generate path like this:
  # /uploads/ckeditor/AhbB1sHOgZmIjIyMDEyLzExLzIzLzE3XzIxXzAwXzY0OF9zdXJ2ZWlsbGFuY2VfbmNjbi5wbmdbCDoGcDoKdGh1bWJJI.something.png
  url_format '/uploads/ckeditor/:job/:basename.:format'

  # some image from previous version can break without this
  verify_urls false
  plugin :imagemagick

  # required if you want use paths from previous version
  allow_legacy_urls true

  # "secure" if images needs this
  secret 'ce649ceaaa953967035b113647ba56db19fd263fc2af77737bae09d452ad769d'

  datastore :file,
            root_path: Rails.root.join('public', 'system','uploads', 'ckeditor', Rails.env),
            server_root: Rails.root.join('public')
end

Rails.application.middleware.use Dragonfly::Middleware, :ckeditor

这将以(旧样式)存储图像:

{Rails.root}/public/system/uploads/ckeditor/{development,production,etc...}
于 2015-02-03T13:55:54.260 回答