0
votes

I'm using rails 5 api and am trying to implement a ckeditor wysiwyg in a form using angularjs 1. I'm using rails 5.1.4, ckeditor 4.2 and paperclip 5.1.0.

I have followed the directions from here: https://github.com/galetahub/ckeditor for the gem implementation and have run the generator:

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

When trying to "Browse Server" or upload an image to the server through the ckeditor I am performing the following Get request:

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

And I then get the following error:

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)>'

This is the controller where the error is coming from: https://github.com/galetahub/ckeditor/blob/master/app/controllers/ckeditor/application_controller.rb

Edit: Turns out the rails 5 api does not include ActionView::Layouts out of the box, so I added this following to my ApplicationController:

include ::ActionView::Layouts

This took care of the undefined method 'layout'. However, now I have another error coming from the same ckeditor controller after the Get request has been passed to the index action. I am also using devise_token_auth and pundit for authorization and authentication.

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>):
1
Right now I have a temporary fix. First of all, the issue lies with the ActionController::API. I could not figure out immediately which modules need to be included to make it all run smoothly. So, for now I've changed ActionController::API to ActionController:Base to include all the associated modules of base. I'll update this answer by switching my controller ancestor back to API and include the necessary modules when I have time. If someone else has this figured out, please feel free to answer :) - S Sanford

1 Answers

0
votes

this is the CKeditor Application Controller where you get the error, you should include this code to your question with 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

I don't know why it is not working and I don't have any idea what Ckeditor.controller_layout is.. keep me updated with your progress