2014-10-30 46 views
3

我不想在我的Rails-App中使用CKEditor。rails 4如何配置ckeditor 4.1

在我的Gemfile

我加入這一行

gem 'ckeditor', :git => 'https://github.com/galetahub/ckeditor.git' 

後,我跑「捆綁更新」和「軌產生的CKEditor:安裝--orm = active_record --backend =回形針」我添加到我的application.js這條線:

//= require ckeditor/init 
在我看來

我加入這一行:

<%= f.cktext_area :img, :ckeditor => {:toolbar => 'img', :customConfig => asset_path('ckeditor/config.js')} %> 

我創造了這個文件夾和網絡連接萊:

/app/assets/javascripts/ckeditor 
/app/assets/javascripts/ckeditor/config.js 
/app/assets/javascripts/ckeditor/contents.css 

我config.js看起來是這樣的:

CKEDITOR.editorConfig = function(config) 
{ 
    config.toolbar_img = [ 
     { name: 'document', items: [ 'Source', '-', 'NewPage', 'Preview', '-', 'Templates' ] }, 
    ] 
} 

爲什麼我的編輯器看起來像這樣? ckeditor

+1

什麼是你希望它是什麼? – Surya 2014-10-30 17:54:04

+0

爲什麼它有這麼多工具欄?我不想只有新建頁面和預覽按鈕:) – Evolutio 2014-10-30 17:56:00

+0

CKEditor中的'New Page'和'Preview button'在哪裏?你能發佈鏈接到你的代碼中添加的文檔配置嗎? – Surya 2014-10-30 18:00:19

回答

5

更改您的config.js文件,這樣的:

CKEDITOR.config.toolbar= [ 
    { name: 'document', items: [ 'Source', '-', 'NewPage', 'Preview', '-', 'Templates' ] } 
]; 

確保您需要config.js在你的application.js文件:

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

此外,CSS文件應這裏:/app/assets/stylesheets/ckeditor/contents.css不在這裏/app/assets/javascripts/ckeditor/contents.css

做完上面提到的更改後,您可以執行:<%= f.cktext_area :img %>

但是,如果你想通過在text_area配置值直接再像這樣應該做的:

<%= f.cktext_area :img, :ckeditor => {:toolbar => 'mini'} %> 

或:

<%= f.cktext_area :img, :ckeditor => {:toolbar => {'name' => 'document', 'items' => ['Source']} } %> 
+0

不行,沒有工作。我不明白,爲什麼我的代碼與您的添加不起作用。 – Evolutio 2014-10-30 18:15:56

+0

同樣的事情爲我工作。你刪除了其他代碼嗎?另外請確保你在application.js – Surya 2014-10-30 18:19:00

+0

需要配置文件是的,我用你的代碼更新了我的代碼。還有老編輯。 – Evolutio 2014-10-30 18:20:01

1

鑑於:

 <%= k.cktext_area :template_text, required: true, :class =>"emailBodyTemplate", :id => "emailBodyText", placeholder: "Email Body Text", :maxlength => 255 %> 

在app/assets/javascripts/ckeditor/config.js:

CKEDITOR.editorConfig = function (config) { 
    config.toolbar_mini = [ 
    ["Bold", "Italic", "Underline", "Strike", "-"], 
    ['BulletedList','NumberedList' ],['Outdent','Indent'], 
    ]; 
    config.toolbar = "mini"; 
    config.toolbarLocation = 'bottom'; 
    config.height = 280;  
    config.width = 620;  
    config.removePlugins = 'elementspath';config.removePlugins = 'elementspath'; 
} 

輸出:

customized CKEditor

+0

謝謝!但是3年已經來不及了:D – Evolutio 2017-12-11 19:28:40