我们有办法禁用操作文本的附件吗?类似下面的 has_rich_text :content, attachment: false
因此,我们可以从 db 中删除 active_storage_blob、active_storage_attachments 表。在这种情况下,只有 action_text_rich_texts 表才能满足目的。
我们有办法禁用操作文本的附件吗?类似下面的 has_rich_text :content, attachment: false
因此,我们可以从 db 中删除 active_storage_blob、active_storage_attachments 表。在这种情况下,只有 action_text_rich_texts 表才能满足目的。
绝对地!
window.addEventListener("trix-file-accept", function(event) {
event.preventDefault()
alert("File attachment not supported!")
})
.trix-button-group--file-tools { display: none !important; }
更重要的是,这是在实际应用程序中完成的提交(前 2 个文件):
https://github.com/yshmarov/pikaburuby/commit/77aaa3e072de943470e4bd2c2b3512727c30232d
我编写了一个可用于后端部分的自定义验证器:
class NoAttachmentsValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
if value.body.attachments.any?
record.errors[attribute] << I18n.t('errors.messages.attachments_not_allowed')
end
end
end
您可以将此代码保存到名为 no_attachments_validator.rb 的文件中,然后在模型中使用它,如下所示:
validates :content, no_attachments: true
这与 Yshmarov 提出的前端修改相结合,效果相当好。