summernote-rails
summernote-rails copied to clipboard
Active Storage example
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.
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);
}
}
});
}
});
Is it possible to have an image picker to select images already uploaded to the app's asset model?