Open sedubois opened 6 months ago
Here is a demo for Action Text:
class Page < ApplicationRecord
include ActiveSnapshot
has_rich_text :body
has_snapshot_children do
instance = self.class.includes(:rich_text_body).find(id)
{ rich_text_body: instance.rich_text_body }
end
end
I manage to create the snapshot but again not to restore it.
Demo with translated Action Text:
class Page < ApplicationRecord
extend Mobility
include ActiveSnapshot
translates :body, backend: :action_text # Using https://github.com/sedubois/mobility-actiontext/
has_snapshot_children do
instance = self.class.includes(:rich_text_body).find(id)
{ rich_text_body: instance.rich_text_body }
end
end
Thank you for this gem! I am evaluating it to track attributes which PaperTrail does not track properly.
Using Mobility, with the default installation (key-value backend), how do I track translated attributes (without having conflicts between different locales and in a way where records can be restored)?
I tried this:
If I have e.g. 2 locales and ensure that the page has a
title
value in each of those 2 locales, then callingsnapshot = page.create_snapshot!
successfully creates 3 snapshot items: one for the main record and one for each of the associated string_translations. This is good news because I hadn't managed to do this so far with Paper Trail or Audited (but I would be happy to be proven wrong.)However when calling
snapshot.restore!
I get the errorPG::UniqueViolation: ERROR: duplicate key value violates unique constraint "pages_pkey"
.Questions:
title
attribute instead of referring tostring_translations
which is meant to be an implementation detail? As the name suggests, Mobility is supposed to allow flexibly using different types of backends and the association namestring_translations
is only applicable to its key-value backend.has_snapshot_children
tohas_associated_snapshots
or similar?Finally, I need to combine all 3 aspects: snapshots for Action Text rich texts which are translated. I manage to translate Action Text rich texts using this gem I built. I could try combining it with this gem when I have more clarifications on the questions above.