2013-06-21 82 views
5

我正在使用CKEditor和CKEditor gem(https://github.com/galetahub/ckeditor),並且一切正常,直到我嘗試添加自定義工具欄爲止。添加自定義工具欄到CKEditor in rails

我見過的一些帖子建議使用config.js文件。但是,按照說明安裝,app/assets/javascripts中沒有/ckeditor/config.js文件。另外,如果我將/ckeditor/config.js添加到javascripts目錄,文件上傳功能將停止工作。即使config.js是空文件,也會發生這種情況。重新啓動服務器後,「上傳」選項卡將變爲隱藏且無法使用。

有沒有一種方法可以普遍定製工具欄?甚至如果我可以配對下來的選項在線或東西,將是有益的......

使用Rails 3.2.11

在我的Gemfile我:

gem "jquery-rails", "~> 2.2.1" 
gem "ckeditor" 
gem "carrierwave" 
gem "mini_magick" 
gem "cloudinary" 

在application.rb中我有:

config.autoload_paths += %W(#{config.root}/app/models/ckeditor) 

在應用程序。 JS我有:

//= require jquery 
//= require jquery_ujs 
//= require bootstrap 
//= require ckeditor/init 
//= require_tree ../../../vendor/assets/javascripts/. 
//= require_tree . 

在我的表單中我有:

= f.cktext_area :content 

config.js文件我嘗試使用:

CKEDITOR.editorConfig = function(config) { 
    config.toolbar_Custom = [ 
    { name: 'document', items : [ 'Source','-','Save','NewPage','DocProps','Preview','-','Templates' ] }, 
    { name: 'clipboard', items : [ 'PasteFromWord','-','Undo','Redo' ] }, 
    { name: 'insert',  items : [ 'Image','Table','HorizontalRule','SpecialChar','PageBreak' ] }, 
    { name: 'tools',  items : [ 'Maximize', 'ShowBlocks','-','About' ] }, 
    '/', 
    { name: 'basicstyles', items : [ 'Bold','Italic','Underline','Strike','Subscript','Superscript','-','RemoveFormat' ] }, 
    { name: 'paragraph', items : [ 'NumberedList','BulletedList','-','Outdent','Indent','-','Blockquote','-','JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-','BidiLtr','BidiRtl' ] }, 
    { name: 'links',  items : [ 'Link','Unlink','Anchor' ] }, 
    '/', 
    { name: 'styles',  items : [ 'Styles','Format','Font','FontSize' ] }, 
    { name: 'colors',  items : [ 'TextColor','BGColor' ] } 
    ]; 

    config.toolbar = 'Custom'; 
}; 

回答

1

你必須創建自己手動配置.js文件。爲了保存上傳選項卡,請在CKEditor的寶石回購這一問題,這也解釋瞭如何解決這個問題:

https://github.com/galetahub/ckeditor/issues/238

,只要貼上引用的配置JavaScript來實現filebrowser到您的config.js文件,並上傳標籤將返回完整的功能。