Ruby on rails 4 使用CKEditor gem、曲别针Rails 4在UI中没有图像上载功能

Ruby on rails 4 使用CKEditor gem、曲别针Rails 4在UI中没有图像上载功能,ruby-on-rails-4,ckeditor,paperclip,Ruby On Rails 4,Ckeditor,Paperclip,我使用的是ckeditor gem(),还有回形针gem,ckeditor可以工作,但是当我单击图像按钮时,我没有上传图像的选项,只能输入一个URL。我找不到任何文档来解释如何使用曲别针和Rails 4实现这一点。我也尝试使用ckeditor进行图像上传,但实际上我切换到了,它是基于ckeditor构建的,但可以更好地处理图像上传。我将它与Carrierwave和Rails 4一起使用,但rich也与回形针兼容(后来它实际上添加了Carrierwave支持)。有一个描述此问题的示例: 一个解决方

我使用的是ckeditor gem(),还有回形针gem,ckeditor可以工作,但是当我单击图像按钮时,我没有上传图像的选项,只能输入一个URL。我找不到任何文档来解释如何使用曲别针和Rails 4实现这一点。

我也尝试使用ckeditor进行图像上传,但实际上我切换到了,它是基于ckeditor构建的,但可以更好地处理图像上传。我将它与Carrierwave和Rails 4一起使用,但rich也与回形针兼容(后来它实际上添加了Carrierwave支持)。

有一个描述此问题的示例:


一个解决方案是从复制config.js的内容。

您可以尝试一下
ckeditor imgur
gem,它会将您的图像保存到imgur,以免费、方便的方式上传图像


只需修改配置即可。来自@KrauseFx的解决方案

    /*
     Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
     For licensing, see LICENSE.html or http://ckeditor.com/license
     */

    CKEDITOR.editorConfig = function( config )
    {
        // Define changes to default configuration here. For example:
        // config.language = 'fr';
        // config.uiColor = '#AADC6E';

        /* Filebrowser routes */
        // The location of an external file browser, that should be launched when "Browse Server" button is pressed.
        config.filebrowserBrowseUrl = "/ckeditor/attachment_files";

        // The location of an external file browser, that should be launched when "Browse Server" button is pressed in the Flash dialog.
        config.filebrowserFlashBrowseUrl = "/ckeditor/attachment_files";

        // The location of a script that handles file uploads in the Flash dialog.
        config.filebrowserFlashUploadUrl = "/ckeditor/attachment_files";

        // The location of an external file browser, that should be launched when "Browse Server" button is pressed in the Link tab of Image dialog.
        config.filebrowserImageBrowseLinkUrl = "/ckeditor/pictures";

        // The location of an external file browser, that should be launched when "Browse Server" button is pressed in the Image dialog.
        config.filebrowserImageBrowseUrl = "/ckeditor/pictures";

        // The location of a script that handles file uploads in the Image dialog.
        config.filebrowserImageUploadUrl = "/ckeditor/pictures";

        // The location of a script that handles file uploads.
        config.filebrowserUploadUrl = "/ckeditor/attachment_files";

        config.allowedContent = true;

        // Rails CSRF token
        config.filebrowserParams = function(){
            var csrf_token, csrf_param, meta,
                metas = document.getElementsByTagName('meta'),
                params = new Object();

            for ( var i = 0 ; i < metas.length ; i++ ){
                meta = metas[i];

                switch(meta.name) {
                    case "csrf-token":
                        csrf_token = meta.content;
                        break;
                    case "csrf-param":
                        csrf_param = meta.content;
                        break;
                    default:
                        continue;
                }
            }

            if (csrf_param !== undefined && csrf_token !== undefined) {
                params[csrf_param] = csrf_token;
            }

            return params;
        };

        config.addQueryString = function( url, params ){
            var queryString = [];

            if ( !params ) {
                return url;
            } else {
                for ( var i in params )
                    queryString.push( i + "=" + encodeURIComponent( params[ i ] ) );
            }

            return url + ( ( url.indexOf( "?" ) != -1 ) ? "&" : "?" ) + queryString.join( "&" );
        };

        // Integrate Rails CSRF token into file upload dialogs (link, image, attachment and flash)
        CKEDITOR.on( 'dialogDefinition', function( ev ){
            // Take the dialog name and its definition from the event data.
            var dialogName = ev.data.name;
            var dialogDefinition = ev.data.definition;
            var content, upload;

            if (CKEDITOR.tools.indexOf(['link', 'image', 'attachment', 'flash'], dialogName) > -1) {
                content = (dialogDefinition.getContents('Upload') || dialogDefinition.getContents('upload'));
                upload = (content == null ? null : content.get('upload'));

                if (upload && upload.filebrowser && upload.filebrowser['params'] === undefined) {
                    upload.filebrowser['params'] = config.filebrowserParams();
                    upload.action = config.addQueryString(upload.action, upload.filebrowser['params']);
                }
            }
        });

        // Toolbar groups configuration.
        config.toolbar = [
            { name: 'document', groups: [ 'mode', 'document', 'doctools' ], items: [ 'Source'] },
            { name: 'clipboard', groups: [ 'clipboard', 'undo' ], items: [ 'Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo' ] },
            // { name: 'editing', groups: [ 'find', 'selection', 'spellchecker' ], items: [ 'Find', 'Replace', '-', 'SelectAll', '-', 'Scayt' ] },
            // { name: 'forms', items: [ 'Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField' ] },
            { name: 'links', items: [ 'Link', 'Unlink', 'Anchor' ] },
            { name: 'insert', items: [ 'Image', 'Flash', 'Table', 'HorizontalRule', 'SpecialChar' ] },
            { name: 'paragraph', groups: [ 'list', 'indent', 'blocks', 'align', 'bidi' ], items: [ 'NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Blockquote', 'CreateDiv', '-', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock' ] },
            '/',
            { name: 'styles', items: [ 'Styles', 'Format', 'Font', 'FontSize' ] },
            { name: 'colors', items: [ 'TextColor', 'BGColor' ] },
            { name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ], items: [ 'Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'RemoveFormat' ] }
        ];

        config.toolbar_mini = [
            { name: 'paragraph', groups: [ 'list', 'indent', 'blocks', 'align', 'bidi' ], items: [ 'NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Blockquote', 'CreateDiv', '-', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock' ] },
            { name: 'styles', items: [ 'Font', 'FontSize' ] },
            { name: 'colors', items: [ 'TextColor', 'BGColor' ] },
            { name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ], items: [ 'Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'RemoveFormat' ] },
            { name: 'insert', items: [ 'Image', 'Table', 'HorizontalRule', 'SpecialChar' ] }
        ];
    };
/*
版权所有(c)2003-2011,CKSource-Frederico Knabben。版权所有。
有关许可,请参阅LICENSE.html或http://ckeditor.com/license
*/
CKEDITOR.editorConfig=函数(配置)
{
//在此处定义对默认配置的更改。例如:
//config.language='fr';
//config.uiColor='#AADC6E';
/*文件浏览器路由*/
//按下“浏览服务器”按钮时应启动的外部文件浏览器的位置。
config.filebrowserBrowseUrl=“/ckeditor/attachment_files”;
//外部文件浏览器的位置,在Flash对话框中按下“浏览服务器”按钮时应启动该浏览器。
config.filebrowserFlashBrowseUrl=“/ckeditor/attachment_files”;
//在Flash对话框中处理文件上载的脚本的位置。
config.filebrowserFlashUploadUrl=“/ckeditor/attachment_files”;
//外部文件浏览器的位置,在“图像”对话框的“链接”选项卡中按下“浏览服务器”按钮时应启动该浏览器。
config.filebrowserImageBrowseLinkUrl=“/ckeditor/pictures”;
//外部文件浏览器的位置,在图像对话框中按下“浏览服务器”按钮时应启动该浏览器。
config.filebrowserImageBrowseUrl=“/ckeditor/pictures”;
//在“图像”对话框中处理文件上载的脚本的位置。
config.filebrowserImageUploadUrl=“/ckeditor/pictures”;
//处理文件上载的脚本的位置。
config.filebrowserUploadUrl=“/ckeditor/attachment_files”;
config.allowedContent=true;
//Rails CSRF令牌
config.filebrowserParams=函数(){
var csrf_令牌、csrf_参数、元、,
metas=document.getElementsByTagName('meta'),
params=新对象();
对于(变量i=0;i-1){
content=(dialogDefinition.getContents('Upload')| | dialogDefinition.getContents('Upload'));
upload=(content==null?null:content.get('upload');
if(upload&&upload.filebrowser&&upload.filebrowser['params']==未定义){
upload.filebrowser['params']=config.filebrowserParams();
upload.action=config.addQueryString(upload.action,upload.filebrowser['params']);
}
}
});
//工具栏组配置。
config.toolbar=[
{name:'document',组:['mode','document','doctools'],项:['Source']},
{name:'clipboard',组:['clipboard','undo'],项:['Cut','Copy','Paste','PasteText','PasteFromWord','-','undo','Redo']},
//{name:'editing',组:['find','selection','spellchecker'],项:['find','Replace','-','SelectAll','-','Scayt']},
//{name:'forms',items:['Form','Checkbox','Radio','TextField','textare','Select','Button','ImageButton','HiddenField']},
{name:'links',项:['Link','Unlink','Anchor']},
{name:'insert',项:['Image','Flash','Table','HorizontalRule','SpecialChar']},
{name:'段落',组:['list',indent','blocks','align','bidi'],项:['NumberedList','BulletedList','-','Outdent','indent','-','Blockquote','CreateDiv','-','JustifyLeft','justifCenter','justifRight','justifBlock'],
'/',
{name:'styles',items:['styles','Format','Font','F