Skip to content
This repository has been archived by the owner on Aug 10, 2021. It is now read-only.

Does not support activestorage #139

Open
laoyouzi opened this issue Nov 8, 2018 · 1 comment
Open

Does not support activestorage #139

laoyouzi opened this issue Nov 8, 2018 · 1 comment

Comments

@laoyouzi
Copy link

laoyouzi commented Nov 8, 2018

No description provided.

@Kulgar
Copy link

Kulgar commented Aug 23, 2019

Spree editor relies on ckeditor gem, they added activestorage support only since last month, and it isn't within a release yet...

So I'd suggest to fork the spree_editor gem and update ckeditor dependency to

s.add_dependency 'ckeditor', '~> 5.0.0'

And then, in your Gemfile, use the version of ckeditor that adds Active Storage support:
gem 'ckeditor', github: 'galetahub/ckeditor', branch: 'master', ref: '4385f23b90f84c25f7b912bd75c233c8f27b5f58'

After bundle install, run the generator:

rails generate ckeditor:install --orm=active_record --backend=active_storage

You will also have to update the following things in your own spree_editor version or in your spree app:

In config/initializers/ckeditor.rb, you have to add these lines:

  config.authorize_with :cancancan, Spree::Ability

  # Asset model classes
  config.picture_model { Ckeditor::Picture }
  config.attachment_file_model { Ckeditor::AttachmentFile }

    # //cdn.ckeditor.com/<version.number>/<distribution>/ckeditor.js | distributions available here: https://ckeditor.com/cke4/presets-all
    config.cdn_url = "//cdn.ckeditor.com/4.11.3/standard/ckeditor.js"

In app/views/shared/editor_engine/_ck_editor.html.erb replace:

<%= javascript_include_tag Ckeditor.cdn_url %>

<script>
  $(function() {
    <% ids.each do |id| %>
      if ($("#<%= id %>").length > 0) {
        CKEDITOR.replace("<%= id %>");
      }
    <% end %>
  });
</script>

By:

<%= javascript_include_tag Ckeditor.cdn_url %>
<%= javascript_include_tag 'ckeditor/config.js' %>

  <script>
    $(function() {
      <% ids.each do |id| %>
        if ($("#<%= id %>").length > 0) {
          CKEDITOR.replace("<%= id %>", editorConfig);
        }
      <% end %>
    });
  </script>

And then in ckeditor/config.js:

editorConfig = {
  filebrowserBrowseUrl: "/ckeditor/attachment_files",
  filebrowserFlashBrowseUrl: "/ckeditor/attachment_files",
  filebrowserFlashUploadUrl: "/ckeditor/attachment_files",
  ...
};

They removed the init.js.erb file... so that solution works if you use the CDN. And it will allow you to easily update ckeditor through your initializer file.

And that's should be it.

We can't do a pull request until ckeditor has released a new official version supporting active storage. But as soon as ckeditor gem will have a new official release supporting active support, creating a PR would be a good thing to do for this gem ^^

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants