我用我的基本模型文章很好地设置了Paper Trail Gem,其中有一个名为body
的text
列。但是,在我将Action Text实现到我的应用程序中并从Article模型中删除列body
之后,**我无法让Paper Trail跟踪关联的body
列中的更改。**我如何才能让它工作?
免责声明:我是Rails的新手。
Article.rb
...
has_rich_text :body
has_paper_trail
...
Articles Schema(删除后:body列)
create_table "articles", force: :cascade do |t|
t.string "title"
t.string "slug"
t.datetime "archived_at"
t.datetime "published_at"
...
end
操作文本架构
create_table "action_text_rich_texts", force: :cascade do |t|
t.string "name", null: false
t.text "body"
t.string "record_type", null: false
t.bigint "record_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["record_type", "record_id", "name"], name: "index_action_text_rich_texts_uniqueness", unique: true
end
我想返回相同的功能,以应用程序之前,我能够看到的变化,在身体的文章。例如,某人添加了一个句子,删除了一个单词等。
6条答案
按热度按时间zd287kbt1#
把这些答案结合起来对我来说很有效:
在
lib/rich_text_paper_trail.rb
和确保这个文件被加载!例如,明确要求:require 'rich_text_paper_trail'
tyu7yeag2#
尝试使用以下命令添加
config/initializers/rich_text_paper_trail.rb
文件:qacovj5a3#
在尝试了这里提供的所有选项后,我想到了一个解决方案,最终效果非常好。
我所做的是我只是用纯Trix Editor版本替换Action Text,因此我能够在我的article.rb模型中保留
:body
,保存整个对象的版本并显示差异。好耶!🎉2w3kk1z54#
Ruby允许您(无论好坏)动态地对事物进行修改。
把它放在一个初始化器中:
6g8kf2rb5#
我们已经在Rails 5.2上使用活动文本的归档版本做了类似的事情。
Gemfile
models/article.rb
helpers/编辑器助手.rb
然后,我们从cdn安装了xml1.1版,并使用了标准的trix-attachments.js和Direct xmlads。
希望升级到Rails 6,如果可能的话,保持这个概念。
vof42yt16#
我受到这个solution的启发,只是将其更改为使用PaperTrail::Version来存储更改。