【问题标题】:Rails 5, Ckeditor and Paperclip error when loading and searching for images加载和搜索图像时出现 Rails 5、Ckeditor 和 Paperclip 错误
【发布时间】:2017-10-24 02:04:04
【问题描述】:

我正在使用 rails 5 api,并尝试使用 angularjs 1 以一种形式实现 ckeditor wysiwyg。我正在使用 rails 5.1.4、ckeditor 4.2 和回形针 5.1.0。

我已按照此处的指示:https://github.com/galetahub/ckeditor 进行 gem 实现并运行了生成器:

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

当尝试“浏览服务器”或通过 ckeditor 将图像上传到服务器时,我正在执行以下 Get 请求:

Started GET "/ckeditor/pictures?CKEditor=js-ckeditor&CKEditorFuncNum=1&langCode=en" for 172.23.0.1 at 2017-10-24 01:59:04 +0000

然后我得到以下错误:

ActionController::RoutingError (undefined method `layout' for Ckeditor::ApplicationController:Class):

ckeditor (4.2.4) app/controllers/ckeditor/application_controller.rb:2:in `<class:ApplicationController>'
ckeditor (4.2.4) app/controllers/ckeditor/application_controller.rb:1:in `<top (required)>'

这是错误来自的控制器:https://github.com/galetahub/ckeditor/blob/master/app/controllers/ckeditor/application_controller.rb

编辑: 原来 rails 5 api 不包括 ActionView::Layouts 开箱即用,所以我将以下内容添加到我的 ApplicationController:

include ::ActionView::Layouts

这处理了未定义的方法“布局”。但是,现在在将 Get 请求传递给 index 操作后,我又遇到了来自同一个 ckeditor 控制器的另一个错误。 我还使用 devise_token_auth 和 pundit 进行授权和身份验证。

Processing by Ckeditor::PicturesController#index as HTML

Parameters: {"CKEditor"=>"js-ckeditor", "CKEditorFuncNum"=>"1", "langCode"=>"en"}

Completed 500 Internal Server Error in 149ms (ActiveRecord: 0.0ms)

NoMethodError (undefined method `ckeditor_authorize!' for #<Ckeditor::PicturesController:0x007f5e7ac7dc30>):

【问题讨论】:

  • 现在我有一个临时修复。首先,问题在于 ActionController::API。我无法立即弄清楚需要包含哪些模块才能使其顺利运行。所以,现在我已经将 ActionController::API 更改为 ActionController:Base 以包含所有相关的 base 模块。我将通过将我的控制器祖先切换回 API 来更新这个答案,并在我有时间时包含必要的模块。如果其他人已经解决了这个问题,请随时回答:)

标签: ruby-on-rails ckeditor paperclip


【解决方案1】:

这是您收到错误的 CKeditor 应用程序控制器,您应该使用 link to the page 将此代码包含在您的问题中

class Ckeditor::ApplicationController < Ckeditor.parent_controller.constantize
  layout Ckeditor.controller_layout

  before_action :find_asset, only: [:destroy]
  before_action :ckeditor_authorize!
  before_action :authorize_resource

  protected

  def respond_with_asset(asset)
    asset_response = Ckeditor::AssetResponse.new(asset, request)

    if asset.save
      render asset_response.success(config.relative_url_root)
    else
      render asset_response.errors
    end
  end
end

我不知道为什么它不起作用,我也不知道Ckeditor.controller_layout 是什么.. 让我了解您的最新进展

【讨论】:

    猜你喜欢
    • 2020-12-01
    • 2018-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多