我有一个使用 ActiveStorage(文章附加的图片)和 froala 编辑器的 rails 6 应用程序。两者都上传到 S3。
但我目前使用的是 froala S3 上传和主动存储。在表格中,我有:
- 上传按钮,允许上传 pdf 文件和
- 带有 froala 的文本字段,可以在其中上传图像
主动存储
class Article < ApplicationRecord
belongs_to :author
has_one_attached :image
#ArticleController
@article.image.attach(params[:image])
弗拉拉:
# class Adm::ArticleController < ApplicationController
def new
#....
@aws_data = FroalaEditorSDK::S3.data_hash(Article.froalaoptions)
end
end
并在javascript中初始化:
var editor = new FroalaEditor('#article_contenu',{
attribution: false,
height: 330,
key: "mykey",
iframeStyleFiles: ['my.css'],
pluginsEnabled: ['image'],
imageUploadToS3: <%= @aws_data.to_json.html_safe %>,
saveURL: '<%= adm_auteur_article_autosave_url %>',
saveMethod: 'POST'
});
我想做类似的事情:
var editor = new FroalaEditor('#article_contenu',{
attribution: false,
height: 330,
key: "mykey",
iframeStyleFiles: ['my.css'],
pluginsEnabled: ['image'],
// imageUploadToS3: <%= @aws_data.to_json.html_safe %>,
saveURL: '<%= rails_blob_path(article.image, disposition: "attachment")%>
});
有没有办法使用 Rails Active Storage 在 froala 编辑器中上传文件,类似于 Rails ActionText,其中在 trix 编辑器中上传的图像存储在 ActiveStorage 中?