Upload picture with redactorJS, it isn't displayed in editor, though it is successfully uploads to the server

71 Views Asked by At

I've successfully installed redactorJS, using gem redactor-rails into my Rails project. I have included js and css files to assets. Then, I ran rails generate redactor:install and rails generate redactor:config. It has created models, uploaders, route and migration. The second command created a config.js file:

window.init_redactor = function(){
  var csrf_token = $('meta[name=csrf-token]').attr('content');
  var csrf_param = $('meta[name=csrf-param]').attr('content');
  var params;
  if (csrf_param !== undefined && csrf_token !== undefined) {
      params = csrf_param + "=" + encodeURIComponent(csrf_token);
  }
  $('.redactor').redactor({
        // You can specify, which ones plugins you need.
        // If you want to use plugins, you have add plugins to your
        // application.js and application.css files and uncomment the line below:
        // "plugins": ['fontsize', 'fontcolor', 'fontfamily', 'fullscreen', 'textdirection', 'clips'],
        imageUpload: "/redactor_rails/pictures?" + params,
        imageGetJson :"/redactor_rails/pictures",
        fileUpload: "/redactor_rails/documents?" + params,
        fileGetJson: "/redactor_rails/documents",
        path: "/assets/redactor-rails",
        css :"style.css",
      });
};

$(document).on( 'ready page:load', window.init_redactor );

The problem is that the images are uploaded, but they are not displayed in the editor, and also the src attribute of image tags are blank. Am I missing something, or, maybe, I'm doing everything in a wrong way? Thanks in advance.

EDIT

For some reason, when I go to this route: redactor_rails/pictures so I could get json of images, I get this error:

Mysql2::Error: Unknown column 'redactor_assets.user_id' in 'where clause': SELECT redactor_assets.* FROM redactor_assets WHERE redactor_assets.type IN ('RedactorRails::Picture') AND redactor_assets.user_id = 20

Can't find why is it going to retrieve redactor_assets.user_id.

0

There are 0 best solutions below