Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Active Storage example #75

Open
wykhuh opened this issue Jun 18, 2018 · 2 comments
Open

Active Storage example #75

wykhuh opened this issue Jun 18, 2018 · 2 comments

Comments

@wykhuh
Copy link

wykhuh commented Jun 18, 2018

Hi,

Is there an example of using summernote-rails with Active Storage? In the example app, it looks like you set up Active Storage (did migration, included activestorage in application.js), but ended up using carrier wave.

@WaKeMaTTa
Copy link
Contributor

WaKeMaTTa commented Jun 18, 2018

This is a hint.

The controller will look like:

# frozen_string_literal: true
class AssetController < ApplicationController
  protect_from_forgery except: :create

  def create
    @upload = Asset.new(params)
    authorize @upload
    respond_to do |format|
      format.json do
        if @upload.save
          render json: { id: @upload.id, url: @upload.url }
        else
          render json: { errors: @upload.errors.messages }
        end
      end
    end
  end
end

The javascript will be like:

({
  sendFile: function(upload_path, file, toSummernote) {
    var data;
    data = new FormData;
    data.append('upload[asset]', file);
    $.ajax({
      data: data,
      type: 'POST',
      url: upload_path,
      cache: false,
      contentType: false,
      processData: false,
      success: function(data) {
        console.log('file uploading...');
        if (typeof data.errors !== 'undefined' && data.errors !== null) {
          console.log('ops! errors...');
          return $.each(data.errors, function(key, messages) {
            return $.each(messages, function(key, message) {
              return alert(message);
            });
          });
        } else {
          console.log('inserting image in to editor...');
          return toSummernote.summernote('insertImage', data.url);
        }
      }
    });
  }
});

@asecondwill
Copy link

Is it possible to have an image picker to select images already uploaded to the app's asset model?

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

No branches or pull requests

3 participants