Skip to content
Mitsuhiro Shibuya edited this page Aug 3, 2019 · 13 revisions

To use the CKEditor with Upload function, add Rails-CKEditor to your Gemfile (gem 'ckeditor') and follow Rails-CKEditor installation instructions.

You can configure more options of CKEditor "config.js" file following the Api Documentation .

RailsAdmin.config do |config|
  config.model Team do
    edit do
      # For RailsAdmin >= 0.5.0
      field :description, :ck_editor
      # For RailsAdmin < 0.5.0
      # field :description do
      #   ckeditor true
      # end
    end
  end
end

Configuration

CKEditor accepts various options, you can configure them in following way:

field :description, :ck_editor do
  config_js ActionController::Base.helpers.asset_path('your_ckeditor_config.js')
end

Misc

Although ckeditor is loaded in modal windows (e.g. twb), by default changes are not saved by submitting the modal. This is because the underlying textarea gets not updated before the ajax post request is issued. To prevent this you can use the following code:

$(document).ready ->
  $(document).on 'mousedown', '.save-action', (e) -> # triggers also when submitting form with enter
    for instance of CKEDITOR.instances
      editor = CKEDITOR.instances[instance]
      if editor.checkDirty()
        editor.updateElement();
    return true;

Add this code to assets/javascripts/rails_admin/custom/ckeditor_ajax.js.coffee and create a file assets/javascripts/rails_admin/custom/ui.js that loads this coffee file into asset pipeline:

//= require rails_admin/custom/ckeditor_ajax

Reminder: It's necessary to configure ckeditor in asset precompile:

Rails.application.config.assets.precompile += ['ckeditor/*']

More here

Clone this wiki locally