Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby on Rails 3.1, Ckeditor custom toolbars. Where to place definitions

I used the gem to install ckeditor. As such there is no config.js in the project (there is in the actual gem folder that I don't want to modify). The install did create a ckeditor.js in the config/initializers folder that would seem to be the correct place to put the tool bar definition. But everything I have tried to get that to work throws a variety of syntax or method not found errors. Has anyone had success with this? If so a quick example would be very helpful.

My current ckeditor.js is:

# Use this hook to configure ckeditor
if Object.const_defined?("Ckeditor")
  Ckeditor.setup do |config|

  # ==> ORM configuration
  # Load and configure the ORM. Supports :active_record (default), :mongo_mapper and
  # :mongoid (bson_ext recommended) by default. Other ORMs may be
  # available as additional gems.
  require "ckeditor/orm/active_record"

  # Allowed image file types for upload.
  # Set to nil or [] (empty array) for all file types
  # config.image_file_types = ["jpg", "jpeg", "png", "gif", "tiff"]

  # Allowed attachment file types for upload.
  # Set to nil or [] (empty array) for all file types
  # config.attachment_file_types = ["doc", "docx", "xls", "odt", "ods", "pdf", "rar", "zip", "tar", "swf"]
  end
end
like image 599
Matthew Doering Avatar asked Apr 23 '12 21:04

Matthew Doering


1 Answers

1.Add following in application.js

//= require ckeditor/ckeditor
//= require_tree ./ckeditor

2.Add a config.js in app/assets/javascript/ckeditor Sample config.js

if(typeof(CKEDITOR) != 'undefined')
{
 CKEDITOR.editorConfig = function(config) {
   config.uiColor = "#AADC6E";
   config.toolbar = [
    [ 'Bold', 'Italic', 'Underline', 'Strike' ],
    [ 'NumberedList', 'BulletedList', 'HorizontalRule' ],
    [ 'Blockquote' ],
    [ 'Undo', 'Redo' ],
    [ 'insertResolved' ],
    [ 'Source' ]
 ];
}
} else{
  console.log("ckeditor not loaded")
}
like image 110
田咖啡 Avatar answered Sep 22 '22 02:09

田咖啡