2014-10-30 41 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