Raphael Cuba edited this page Jul 13, 2017 · 12 revisions
Clone this wiki locally

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

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()
    return true;

Add this code to assets/javascripts/rails_admin/custom/ 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

More here

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

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