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

問題を解決するためにどのようなアイデアがありますか?

UPD。これらのエラーを修正すると、次のようになります。

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

2 に答える 2

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 に答える
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 ') 終了ステータスと標準エラー出力あり dyld: ライブラリがロードされていません: /usr/local/lib/liblzma.5.dylib 参照元: /usr/local/bin/identify 理由: イメージが見つかりません

)

于 2015-04-06T15:47:31.970 に答える